? ? ? ?游戲開發中如果做不到自己編寫的代碼做斷點調試,無不是瞎子摸象,特別是C++這么底層的語言。這2天開始在VS studio中折騰,一直折騰不出結果,幾次想要放棄GODOT。最終今天在VS code中搞定了這斷點調試C++代碼。
? ? ? ?在上一篇文章我已經做好了“GDextension” c++ 插件
? ? ? ?在Godot 4.2中使用GDExtension方式制作C++插件
接下來就是講解vs code斷點調試的配置步驟
1、首先在vs code 中安裝2個插件,
? ? ? 1) 插件名“c/c++” 作者:Microsoft
? ? ? ?2)插件名:"CodeLLDB" 作者 Vadim Chugunov。 這個就是用來做調試的插件
2、用VS code 打開文件夾的方式打開我們的項目工程,注意是根目錄 “gdextension_cpp_example/”。如果提示需要創建工作區,我們不創建工作區。
3、在VS code中點運行,然后在點不搜索框中我們點一下,然后在下拉列表選擇lldb他會報錯提示如下
?我們點擊 “ok”按鈕進入配置 “launch”文件
首次進入配置文件默認如下
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"type": "lldb","request": "launch","name": "Debug","program": "${workspaceFolder}/<executable file>","args": [],"cwd": "${workspaceFolder}"}]
}
我們要做修改,改成如下
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"type": "lldb","request": "launch","preLaunchTask": "build","name": "Debug","program": "D:\\pro\\Godot_v4.2.2-stable_mono_win64\\Godot_v4.2.2-stable_mono_win64.exe","args": ["--path","E:\\godotProject\\gdextension_cpp_example\\demo"],"cwd": "${workspaceFolder}"}]
}
注意:1、program 這項的值是我們godot應用程序的路徑,你要修改成自己的安裝路徑,注意后綴是.exe,然后要把"\",改成雙斜杠"\\".
? ? ? ? ? ?2、--path 路徑是我們項目工程中godot工程的路徑
4、當配置好上面文件,然后我們點擊debug運行,它會再報錯提示,我們沒有配置task.json。
我們點擊 “configure task”按鈕,然后搜索框這里會提示,我們選擇"create task.json file form template",然后再點擊 “orthers” 這類型的任務。修改后的代碼如下
{// See https://go.microsoft.com/fwlink/?LinkId=733558// for the documentation about the tasks.json format"version": "2.0.0","tasks": [{"label": "build","type": "shell","command": "scons -j10 target=template_debug debug_symbols=yes"}]
}
就3項設置,第三項中的 -j10, 就是開啟10線程編譯,如果你的電腦夠好,可以開多點。
完:寫好以上這2個配置文件,然后點debug 運行,就能自動啟動godot游戲窗口,而且我們還能再自己的c++插件代碼中打斷點調試。現在總算是可以進入正常的游戲開發了。