Skip to content

Commit

Permalink
完成计划刻统计
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohengying committed Feb 12, 2022
1 parent cb79f3c commit e8e7d48
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ target_include_directories(
api/language/lang
)

target_link_libraries(${MOD_NAME} ${MOD_API_NAME})
target_link_libraries(${MOD_NAME} ${MOD_API_NAME})
21 changes: 21 additions & 0 deletions api/block/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,28 @@ namespace trapdoor {
//获取方块对象
// Block *getBlock();
};
struct TickNextTickData {
trapdoor::BlockPos pos;
trapdoor::Block* block;
uint64_t tick;
int priorityOffset;
};

struct BlockTick {
bool removed;
TickNextTickData data;
};
struct TickDataSet {
std::vector<BlockTick> queue;
};
struct BlockTickingQueue {
void* owningChunk;
uint64_t currentTick;
TickDataSet next;
TickDataSet active;
bool ueueType;
bool instaTick;
};
} // namespace trapdoor
typedef trapdoor::Block Block;
typedef trapdoor::BlockActor BlockActor;
24 changes: 22 additions & 2 deletions mod/tick/GameTick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,33 @@ THook(void, LevelChunk_tickBlockEntities_41f9b2ca, void *levelChunk,
}

// BlockTickingQueue::pendingTicks
THook(void, BlockTickingQueue_tickPendingTicks_e4625213, void *queue,
trapdoor::BlockSource *source, uint64_t until, int max, bool instalTick) {
THook(void, BlockTickingQueue_tickPendingTicks_e4625213,
trapdoor::BlockTickingQueue *queue, trapdoor::BlockSource *source,
uint64_t until, int max, bool instalTick) {
// if (queue->next.queue.size() != 0 && flag) {
// // printf("Tick = %llu queue size is (%zd,%zu)\n",
// queue->currentTick,
// // queue->next.queue.size(), queue->active.queue.size());
// for (auto &i : queue->next.queue) {
// auto *b = i.data.block;
// printf("[%d %d %d >%s]", i.data.pos.x, i.data.pos.y,
// i.data.pos.z,
// b->getName().c_str());
// }
// printf("\n");
// }

if (mod::tick::gameProfiler.inProfiling) {
TIMER_START
if (!queue->next.queue.empty()) {
auto tickData = queue->next.queue[0].data;
mod::tick::gameProfiler.ptCounter[tickData.pos.toChunkPos()] =
queue->next.queue.size();
}
original(queue, source, until, max, instalTick);
TIMER_END
mod::tick::gameProfiler.chunkPendingTickTime += timeReslut;

} else {
original(queue, source, until, max, instalTick);
}
Expand Down
37 changes: 29 additions & 8 deletions mod/tick/SimpleProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,57 @@ namespace mod {
}
color |= trapdoor::MSG_COLOR::BOLD;

size_t counter = 0;
size_t max = 0;
//根据统计的计划刻队列的长度来打印对应信息
bool existPtOverflow = false;
for (auto &kv : this->ptCounter) {
counter += kv.second;
if (max < kv.second) {
max = kv.second;
}
if (kv.second >= 100) {
existPtOverflow = true;
}
}

auto ptNum =
static_cast<float>(counter * this->totalRound) / tickChunkNum;

builder.sTextF(color, "%.3fms", mspt)
.sTextF(firstLineColor, " TPS: ")
.sTextF(color, "%d", tps)
.sTextF(firstLineColor, " CHUNKS: %d\n",
tickChunkNum / this->totalRound);
.sTextF(firstLineColor, " CHUNKS: %d(pt: %.2f,%u)\n",
tickChunkNum / this->totalRound, ptNum, max);
addShowItem(builder, " - ", "Redstone", totalRedstoneTickTime, mspt);

addShowItem(builder, " - ", "SignalUpdate",
redstoneTickTime / rounds, mspt);
builder.sText(" - ", trapdoor::MSG_COLOR::GRAY)
.text("PendingUpdate: Invalid\n");
addShowItem(builder, " - ", "PendingRemove",
redstonePendingRemoveTime / rounds, mspt);

addShowItem(builder, " - ", "EntitySystem",
levelEntitySystemTickTime / rounds, mspt);
addShowItem(builder, " - ", "Chunk (un)load & village",
dimensionTickTime / rounds, mspt);

addShowItem(builder, " - ", "ChunkTick", chunkTickTime / rounds, mspt);

addShowItem(builder, " - ", "BlockEntities",
chunkBlockEntityTickTime / rounds, mspt);
addShowItem(builder, " - ", "RandomTick",
chunkRandomTickTime / rounds, mspt);

addShowItem(builder, " - ", "PendingTick",
chunkPendingTickTime / rounds, mspt);
builder.broadcast();

if (existPtOverflow) {
builder.text("Here are pending tick overflow chunks:\n");
for (auto &kv : this->ptCounter) {
if (kv.second >= 100) {
builder.sTextF(trapdoor::MSG_COLOR::RED, "[%d,%d] ",
kv.first.x * 16 + 8, kv.first.z * 16 + 8);
}
}
}
builder.broadcast();
// .textF(" - Chunk tick: %.3fms (%d)\n", chunkTickTime / rounds,
// tickChunkNum / totalRound)
// .textF(" - Block entity: %.3fms\n",
Expand Down
5 changes: 5 additions & 0 deletions mod/tick/SimpleProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#define MOD_SIMPLEPROFILER_H

#include <chrono>
#include <map>

#include "entity/Actor.h"
#include "graphics/BlockPos.h"
#include "tools/noncopyable .h"

typedef std::chrono::high_resolution_clock timer_clock;
Expand Down Expand Up @@ -36,9 +38,11 @@ namespace mod {
microsecond_t redstonePendingAddTime = 0;
microsecond_t redstonePendingRemoveTime = 0;
microsecond_t trapdoorModTickTime = 0;
std::map<trapdoor::BlockPos2, size_t> ptCounter;
size_t tickChunkNum = 0;
size_t totalRound = 100;
size_t currentRound = 0;

bool inProfiling = false;

void reset() {
Expand All @@ -57,6 +61,7 @@ namespace mod {
trapdoorModTickTime = 0; //模组自身的更新时间(heavy tick)
tickChunkNum = 0;
currentRound = 0;
this->ptCounter.clear();
}

void print() const;
Expand Down

0 comments on commit e8e7d48

Please sign in to comment.