Skip to content

Commit

Permalink
Updating Entity caching (Part 2) (Add test volatile int)
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Sep 25, 2024
1 parent a346e3b commit 7dab488
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
public final class Cache
{
public static int TickCounter = 0;
public static final int UPDATE_INTERVAL = 1200;
public static volatile int DynamicUpdateInterval = 1200; // Сначала 1200, затем 4800
public static final int FIRST_UPDATE_INTERVAL = 1200; // Первое обновление
public static final int SUBSEQUENT_UPDATE_INTERVAL = 4800; // Последующие обновления

public static boolean isFirstUpdate = true; // Флаг для отслеживания первого обновления
public static boolean isPrimaryPlayerLogged = false; // Флаг для главного игрока

public static final Set<ChunkPos> CACHE_VALID_CHUNKS = new HashSet<>();
public static final Set<EntityAnimal> CACHED_ACTUAL_ANIMALS = new HashSet<>();
public static final Set<EntityAnimal> CACHED_BUFFER_ANIMALS = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,35 @@ public synchronized void onWorldTick_0(TickEvent.WorldTickEvent event)
{
Cache.TickCounter++;

if (Cache.TickCounter >= Cache.UPDATE_INTERVAL)
if (Cache.TickCounter >= Cache.DynamicUpdateInterval)
{
Cache.TickCounter = 0;

Cache.copyActualToBuffer();

Cache.updateCache(event.world);

// Если это первое обновление, то меняем интервал на 4800
if (Cache.isFirstUpdate)
{
Cache.DynamicUpdateInterval = Cache.SUBSEQUENT_UPDATE_INTERVAL;
Cache.isFirstUpdate = false;
}
}
}
}

@SubscribeEvent
public synchronized void onPlayerLoggedIn_1(PlayerEvent.PlayerLoggedInEvent event)
{
if (!Cache.isPrimaryPlayerLogged)
{
Cache.isPrimaryPlayerLogged = true;
Cache.DynamicUpdateInterval = Cache.FIRST_UPDATE_INTERVAL;
Cache.TickCounter = 0; // Сбрасываем счётчик при первом входе
Cache.isFirstUpdate = true;
}


Cache.copyActualToBuffer();
}

Expand Down

0 comments on commit 7dab488

Please sign in to comment.