Skip to content

Commit

Permalink
Merge branch '1.18.2' into 1.19.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Thutmose committed Nov 7, 2022
2 parents 0c100d1 + 21dfeef commit 6e25fbf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 58 deletions.
11 changes: 0 additions & 11 deletions src/main/java/pokecube/core/ai/tasks/combat/CombatTask.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pokecube.core.ai.tasks.combat;

import java.util.Comparator;
import java.util.Map;

import com.google.common.collect.Maps;
Expand Down Expand Up @@ -32,14 +31,4 @@ public CombatTask(final IPokemob pokemob, final Map<MemoryModuleType<?>, MemoryS
{
super(pokemob, RootTask.merge(CombatTask.MEMS, mems));
}

@Override
protected Comparator<MemoryModuleType<?>> getCheckOrder()
{
return (a, b) -> {
int a1 = a == MemoryModules.ATTACKTARGET.get() ? 1 : 0;
int b1 = b == MemoryModules.ATTACKTARGET.get() ? 1 : 0;
return Integer.compare(a1, b1);
};
}
}
45 changes: 45 additions & 0 deletions src/main/java/thut/api/Tracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.IOException;
import java.nio.file.Path;

import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -38,6 +40,49 @@ public static void init()
MinecraftForge.EVENT_BUS.addListener(Tracker::onWorldSave);
}

private static long start = System.nanoTime();
private static long n = 0;
private static long dt = 0;
private static Object2LongArrayMap<Class<?>> taskTimes = new Object2LongArrayMap<>();
private static Object2IntArrayMap<Class<?>> taskNs = new Object2IntArrayMap<>();

public static void timerStart()
{
start = System.nanoTime();
}

public static void timerEnd(Class<?> involved)
{
long _dt = System.nanoTime() - start;
dt += _dt;
taskTimes.compute(involved, (key, value) -> {
if (value == null) value = _dt;
else value += _dt;
return value;
});
taskNs.compute(involved, (key, value) -> {
if (value == null) value = 1;
else value += 1;
return value;
});
n++;
if (n >= 1000000)
{
double avg = dt / ((double) n);
System.out.println("Average time: " + (avg / 1000d) + "us");
System.out.println("class\ttime per\ttime total");
taskTimes.forEach((clazz, val) -> {
double avg2 = val / ((double) taskNs.getInt(clazz));
String key = "%s\t%.2f\t%.2f";
System.out.println(key.formatted(clazz, (avg2 / 1000d), (val / 1000d)));
});
taskTimes.clear();
taskNs.clear();
n = 0;
dt = 0;
}
}

long time = 0;

public Tracker()
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/thut/api/entity/ai/RootTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -186,53 +184,9 @@ protected boolean shouldNotRun(final E mobIn)
return false;
}

static long start = System.nanoTime();
static long n = 0;
static long dt = 0;
static Object2LongArrayMap<Class<?>> taskTimes = new Object2LongArrayMap<>();
static Object2IntArrayMap<Class<?>> taskNs = new Object2IntArrayMap<>();

static void timerStart()
{
start = System.nanoTime();
}

static void timerEnd(Class<?> involved)
{
long _dt = System.nanoTime() - start;
dt += _dt;
taskTimes.compute(involved, (key, value) -> {
if (value == null) value = _dt;
else value += _dt;
return value;
});
taskNs.compute(involved, (key, value) -> {
if (value == null) value = 1;
else value += 1;
return value;
});
n++;
if (n >= 1000000)
{
double avg = dt / ((double) n);
System.out.println("Average time: " + (avg / 1000d) + "us");
System.out.println("class\ttime per\ttime total");
taskTimes.forEach((clazz, val) -> {
double avg2 = val / ((double) taskNs.getInt(clazz));
String key = "%s\t%.2f\t%.2f";
System.out.println(key.formatted(clazz, (avg2 / 1000d), (val / 1000d)));
});
taskTimes.clear();
taskNs.clear();
n = 0;
dt = 0;
}
}

@Override
public boolean hasRequiredMemories(final E mobIn)
{
// timerStart();
// Default to true, everything below will set false.
boolean ret = true;
check:
Expand Down Expand Up @@ -281,7 +235,6 @@ public boolean hasRequiredMemories(final E mobIn)
}
}
this.tempCont = ret;
// timerEnd(this.getClass());
return ret;
}
}

0 comments on commit 6e25fbf

Please sign in to comment.