Skip to content

Commit

Permalink
seperate ASYNC_TASK and PLAYER_ACTION stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Nov 25, 2020
1 parent 1a04223 commit 865bd7a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.world.World;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -54,7 +55,7 @@ public static MicroTimingLoggerManager getInstance()

public Map<ServerWorld, MicroTimingLogger> getLoggers()
{
return loggers;
return this.loggers;
}

public static boolean isLoggerActivated()
Expand Down Expand Up @@ -239,12 +240,6 @@ public static void setTickStageExtra(TickStageExtraBase stage)
}
}

/*
* ------------
* Interfaces
* ------------
*/

private void flush(long gameTime) // needs to call at the end of a gt
{
if (gameTime != this.lastFlushTime)
Expand All @@ -265,8 +260,20 @@ public static void flushMessages(long gameTime) // needs to call at the end of a
}
}

/*
* ------------
* Interfaces
* ------------
*/

public static Optional<TickStage> getTickStage(World world)
{
return getWorldLogger(world).map(MicroTimingLogger::getTickStage);
}

public static Optional<TickStage> getTickStage()
{
Iterator<ServerWorld> iterator = getInstance().getLoggers().keySet().iterator();
return iterator.hasNext() ? getTickStage(iterator.next()) : Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum TickStage
CHUNK_TICK("ChunkTick", true),
TILE_ENTITY("TileEntity", true),
AUTO_SAVE("AutoSave", false),
ASYNC_TASK("AsyncTask", false),
PLAYER_ACTION("PlayerAction", false),
COMMAND_FUNCTION("CommandFunction", false),
NETWORK("Network", false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public PlayerActionTickStageExtra(ServerPlayerEntity player)
public BaseText toText()
{
return Messenger.c(
String.format("w %s\n", this.tr("sync_tasks", "Sync task executions in main thread including player actions")),
String.format("w %s\n", this.tr("player_action", "Executing player actions sent by clients")),
super.toText()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ private void onStageAutosave(CallbackInfo ci)
@Inject(method = "method_16208", at = @At("HEAD"))
private void onStagePlayerAction(CallbackInfo ci)
{
MicroTimingLoggerManager.setTickStage(TickStage.PLAYER_ACTION);
MicroTimingLoggerManager.setTickStage(TickStage.ASYNC_TASK);
}

// reset potential tick stage extra set in NetworkThreadUtilsMixin
// reset potential tick stage (extra) set in NetworkThreadUtilsMixin
@Inject(method = "runTask", at = @At("RETURN"))
void cleanStageExtraInStagePlayerAction(CallbackInfoReturnable<Boolean> cir)
{
MicroTimingLoggerManager.setTickStage(TickStage.ASYNC_TASK);
MicroTimingLoggerManager.setTickStageExtra(null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package carpettisaddition.mixins.logger.microtiming.tickstages;

import carpettisaddition.logging.loggers.microtiming.MicroTimingLoggerManager;
import carpettisaddition.logging.loggers.microtiming.enums.TickStage;
import carpettisaddition.logging.loggers.microtiming.tickstages.PlayerActionTickStageExtra;
import net.minecraft.network.NetworkThreadUtils;
import net.minecraft.network.Packet;
Expand All @@ -26,6 +27,7 @@ private static <T extends PacketListener> void startProcessPacket(Packet<T> pack
if (listener instanceof ServerPlayNetworkHandler)
{
ServerPlayNetworkHandler handler = (ServerPlayNetworkHandler) listener;
MicroTimingLoggerManager.setTickStage(TickStage.PLAYER_ACTION);
MicroTimingLoggerManager.setTickStageExtra(new PlayerActionTickStageExtra(handler.player));
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/carpettisaddition/utils/GameUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ public static long getGameTime()
{
return CarpetTISAdditionServer.minecraft_server.getWorld(DimensionType.OVERWORLD).getTime();
}

public boolean isOnServerThread()
{
return CarpetTISAdditionServer.minecraft_server != null && CarpetTISAdditionServer.minecraft_server.isOnThread();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
"logger.microTiming.stage_detail.thunder": "闪电",
"logger.microTiming.stage_detail.ice&snow": "结冰&积雪",
"logger.microTiming.stage_detail.randomtick": "随机刻",
"logger.microTiming.stage_extra.sync_tasks": "玩家动作等需要同步到主世界线程的任务",
"logger.microTiming.stage_extra.player_action": "执行来自客户端的玩家动作",
"logger.microTiming.stage_extra.ticking_weather_effect_entities": "运算天气实体",
"logger.microTiming.stage_extra.ticking_regular_entities": "运算普通实体",
"logger.microTiming.stage_extra.ticking_player_entity": "运算玩家实体",
Expand Down

0 comments on commit 865bd7a

Please sign in to comment.