Void FX_Window(ImDrawList* d, V2 windowPos, V2 windowSize, float t)
{
const float fontSize = 16.0f;
const int maxCols = 100;
static float colY[maxCols];
static float colSpeed[maxCols];
static char colChars[maxCols][20]; // 预生成每列的字符序列
static float lastUpdate[maxCols]; // 记录上次更新时间
static bool init = false;
if (!init) {
for (int i = 0; i < maxCols; i++) {
colY[i] = (float)(rand() % 100);
colSpeed[i] = 0.05f + (rand() % 100) / 1000.f;
lastUpdate[i] = 0.0f;
// 预生成随机字符序列
for (int j = 0; j < 20; j++) {
colChars[i][j] = (char)(33 + (rand() % 94));
}
}
init = true;
}
int columns = (int)(windowSize.x / (fontSize * 0.8f));
if (columns > maxCols) columns = maxCols;
for (int i = 0; i < columns; i++) {
colY[i] += colSpeed[i] * 1.5f;
if (colY[i] * fontSize > windowSize.y + 300) {
colY[i] = -(float)(rand() % 20);
colSpeed[i] = 0.05f + (rand() % 100) / 1000.f;
// 重置时重新生成字符序列
for (int j = 0; j < 20; j++) {
colChars[i][j] = (char)(33 + (rand() % 94));
}
}
// 每0.1秒才更新一次字符,减少随机计算
if (t - lastUpdate[i] > 0.1f) {
lastUpdate[i] = t;
// 只更新部分字符,不是全部
int updateIdx = rand() % 20;
colChars[i][updateIdx] = (char)(33 + (rand() % 94));
}
int chainLen = 10 + (i % 8);
for (int j = 0; j < chainLen; j++) {
float charY = (colY[i] - j) * fontSize;
if (charY < 0 || charY > windowSize.y) continue;
float xOffset = sin(t * 2.0f + i) * 2.0f;
float alpha = 1.0f - ((float)j / chainLen);
ImU32 color;
if (j == 0)
color = ImColor(200, 255, 200, (int)(alpha * 255));
else
color = ImColor(20, (int)(150 * alpha), 20, (int)(alpha * 200));
// 使用预生成的字符,循环使用
char c = colChars[i][j % 20];
V2 pos = V2(windowPos.x + i * (fontSize * 0.8f) + xOffset, windowPos.y + charY);
d->AddText(NULL, fontSize, pos, color, &c, &c + 1);
}
if ((int)(t * 2) % 50 == 0 && i % 15 == 0) colY[i] += 0.5f;
}
}