Skip to content

Commit

Permalink
添加启用tracy的选项
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Oct 15, 2024
1 parent 52e4585 commit beb24d1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Config {
multiMode: boolean = false;
multiPlayers: number[] = [1, 2];
debugPlayers: number[] = [1];
tracy: boolean = false;
}

export let config = new Config();
15 changes: 14 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,21 @@ class Helper {

private registerCommandOfLaunchGame() {
vscode.commands.registerCommand('y3-helper.launchGame', async () => {
let luaArgs: Record<string, string> = {};

if (config.tracy) {
luaArgs['lua_tracy'] = 'true';
}

await vscode.window.withProgress({
title: '正在启动游戏...',
location: vscode.ProgressLocation.Window,
}, async (progress) => {
let gameLauncher = new GameLauncher();
await gameLauncher.launch({
luaArgs: luaArgs,
multi: config.multiMode ? config.multiPlayers.sort() : undefined,
tracy: config.tracy,
});
});
});
Expand All @@ -199,7 +207,7 @@ class Helper {
}, async (progress) => {
let gameLauncher = new GameLauncher();

let luaArgs: {[key: string]: string} = {};
let luaArgs: Record<string, string> = {};
if (config.multiMode) {
luaArgs['lua_multi_mode'] = 'true';
luaArgs['lua_multi_wait_debugger'] = 'true';
Expand All @@ -212,9 +220,14 @@ class Helper {
luaArgs['lua_wait_debugger'] = 'true';
}

if (config.tracy) {
luaArgs['lua_tracy'] = 'true';
}

let suc = await gameLauncher.launch({
luaArgs: luaArgs,
multi: config.multiMode ? config.multiPlayers.sort() : undefined,
tracy: config.tracy,
});
if (!suc) {
return;
Expand Down
6 changes: 6 additions & 0 deletions src/launchGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface LaunchOptions {
luaArgs?: {[key: string]: string};
multi?: number[];
debugPlayers?: number[];
tracy?: boolean;
}

export class GameLauncher {
Expand Down Expand Up @@ -86,6 +87,11 @@ export class GameLauncher {
vscode.window.showErrorMessage("启动游戏失败!");
return false;
}

if (options?.tracy) {
await y3.tracy.launch();
}

return true;
}
}
15 changes: 14 additions & 1 deletion src/mainMenu/pages/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TreeViewManager } from "../../console/treeView";

function 多开模式() {
let node = new TreeNode('多开模式', {
description: '12月4号版本更新后可用',
description: '12月4号编辑器更新后可用',
tooltip: '请手动启动编辑器登录(并选择30天免登录)再使用此功能',
checkboxState: config.multiMode ? vscode.TreeItemCheckboxState.Checked : vscode.TreeItemCheckboxState.Unchecked,
onDidChangeCheckboxState(state) {
Expand Down Expand Up @@ -60,6 +60,18 @@ function 多开模式() {
return node;
}

function 启用tracy() {
let node = new TreeNode('启用tracy', {
description: '下次编辑器更新后可用',
tooltip: '对Lua进行性能分析,但是会大幅影响运行效率',
checkboxState: config.tracy ? vscode.TreeItemCheckboxState.Checked : vscode.TreeItemCheckboxState.Unchecked,
onDidChangeCheckboxState(state) {
config.tracy = state === vscode.TreeItemCheckboxState.Checked;
},
});
return node;
}

function 切换自定义视图() {
let node = new TreeNode('切换自定义视图', {
iconPath: new vscode.ThemeIcon('window'),
Expand Down Expand Up @@ -166,6 +178,7 @@ export class 功能 extends TreeNode {
},
}),
多开模式(),
启用tracy(),
切换自定义视图(),
]
});
Expand Down
1 change: 1 addition & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { log } from './log';
export * as fs from './fs';
export * as json from './json';
export * as lua from './lua';
export * as tracy from './tracy';
18 changes: 18 additions & 0 deletions src/tools/tracy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as y3 from 'y3-helper';
import * as vscode from 'vscode';
import { runShell } from '../runShell';

export async function launch() {
if (!y3.env.editorUri) {
return false;
}
const tracyUri = vscode.Uri.joinPath(y3.env.editorUri, '../LocalData/Patch/ExternalResource/tracy/Tracy.exe');
if (!await y3.fs.isExists(tracyUri)) {
return false;
}
const code = await runShell('启动 Tracy', `${tracyUri.fsPath}`, [
"-a", "127.0.0.1",
]);

return code === 0;
}

0 comments on commit beb24d1

Please sign in to comment.