Amazon Lumberyard with Visual Code

Before you set up vscode, it’s important to setup Lumberyard first.

Visual Code is a great text editor, but recently it’s been extended to go beyond that limited role.

So why should you use vscode over Visual Studio? Here are some the reasons for me:

  1. Modifying waf files is less headache (no reloading the solution).
  2. No processing lag. When vs is processing stuff, it can make the editor choppy or unusable. Vscode does not have this issue.
  3. Fuzzy searches on symbols and files. If you lookup CB.h it will give you Component Bus.h
  4. No vs filters. This is actually great because it means your file system folders organize your file (good for waf).
  5. Over 9000% simpler design.
  6. Multiple game projects loaded at once.
  7. Integrated terminal with custom tasks are great for using waf.
  8. Powermode extension makes you feel powerful

Sounds great? There are some cons but I still prefer it over Visual Studio.

  1. Intellisense is good but sometimes had trouble with local variables.
  2. Sometimes red squigglies linger but I’ve seem this in VS as well.
  3. You have to manually setup the includes. But I do most of this for you below.
  4. You need visual studio installed because it uses its Intellisense engine.
  5. Debugging will sometimes load the file you are debugging twice into the editor.

Lets Get Downloadin’

First you will want to get vscode (either insiders or stable version.) Be sure to install the Open With Code options in the installer
open-with-code.png

Once that is finished, open it up, and click the extension button on the left
tut_vscode_extensions_button

Here we need to search and install a few extensions:
Required
* C/C++ by Microsoft
* Include Autocomplete
* Toggle Header/Source
* Power Mode – literally unusable without this
Optional
* Clipboard History (Cntrl Shift v will give you the last 10 copies or so)
* Create Unique Ids for creating Guids
* Lumberyard Snippets – Because the author is amazing
* Reloaded C/C++ (install first) and Reloaded Themes (install second) for better syntax colors.

C/C++ needs to install some more, and in order to get it to kick off, we need to open a c++ file. So open any .h or .cpp file anywhere, it doesn’t matter. You should see C/C++ download and finish installing.
tut_vscode_finished_installing.png

Close vscode.

The Solution… er, I mean, Workspace File

So the way my setup works is that I create a VisualCode folder to hold all the general configs, which includes the workspace file.

So create a folder in your dev folder called VisualCode. Inside that folder create a file called ly.code-workspace. This file will contain all the folders we want to open and our common settings.

Your folder structure should look like:
–> dev
—–> VisualCode
——–> ly.code-workspace

ly.code-workspace:

{
    "id": "1503499542888",
    "folders": [
        "file:///c:/w/pa/Lumberyard/1.9.0.1/dev/VisualCode",
    "file:///c:/w/pa/Lumberyard/1.9.0.1/dev/Principia",
        "file:///c:/w/pa/Lumberyard/1.9.0.1/dev/TutorialSeries",
        "file:///c:/w/pa/Lumberyard/1.9.0.1/dev/Code",
        "file:///c:/w/pa/Lumberyard/1.9.0.1/dev/Gems",
        "file:///c:/w/pa/Lumberyard/1.9.0.1/dev/Gems/PhysicsWrapper"

    ],
    "settings": {
        "C_Cpp.intelliSenseEngine": "Default",
        "C_Cpp.autocomplete": "Default",
        "C_Cpp.errorSquiggles": "Enabled",
        "C_Cpp.intelliSenseEngineFallback": "Disabled",
        "terminal.integrated.shell.windows": "C://Windows//System32//cmd.exe",
        "files.associations": {
            "*.waf_files": "json"
        }
    }
}

First, you will need to change c:/w/pa to be wherever you put Lumberyard.

Principia, TutorialSeries, and PhysicsWrapper are my own projects. You will need to change these to be your own projects/gems.

The C_Cpp settings are basically telling the C++ extension to give red error squiggles, to base it on the default intelliSenseEngine (which is Visual Studio’s), to enable autocomplete (also based on VS), and to not fallback on the crappy tag parser intellisense engine.

Save this beast. Now right click the ly.code-workspace file and select, “Open With Code”.

Setting up Compiling and Configuring

You should now see something like this:
tut_vscode_files.png

Expand Visual Code, and add a .vscode folder inside it (you can use vscode to add files/folders.) Create 3 files inside the .vscode folder, that we will need:
1. c_cpp_properties.json
2. launch.json
3. tasks.json

Lets start with c_cpp_properties.json

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/INCLUDE",
                "C:/Program Files (x86)/Windows Kits/10/include/10.0.15063.0/ucrt",
                "${workspaceRoot}/../TutorialSeries/Gem/Code/Source",
                "${workspaceRoot}/../TutorialSeries/Gem/Code/Include",
                "${workspaceRoot}/../Principia/Gem/Code/Source",
                "${workspaceRoot}/../Principia/Gem/Code/Include",
                "${workspaceRoot}/../Code/CryEngine/CryCommon",
                "${workspaceRoot}/../Code/CryEngine/CryAction",
                "${workspaceRoot}/../Code/Framework/AzGameFramework",
                "${workspaceRoot}/../Gems/LmbrCentral/Code/include",
                "${workspaceRoot}/../Gems/PhysicsWrapper/Code/include",
                "${workspaceRoot}/../Code/Framework/AzFramework",
                "${workspaceRoot}/../Code/Framework/GridMate",
                "${workspaceRoot}/../Code/Framework/AzCore",
                "${workspaceRoot}/../Code/Framework/AzTest",
                "${workspaceRoot}/../Code/Framework/AzToolsFramework",
                "${workspaceRoot}/../Code/SDKs/boost",
                "${workspaceRoot}/../Code/SDKs/GoogleMock/include"
            ],
            "defines": [
                "_DEBUG",
                "_WIN32",
                "_WIN64",
                "NOMINMAX",
                "_ITERATOR_DEBUG_LEVEL=2",
                "DEDICATED_SERVER",
                "AZ_TESTS_ENABLED",
                "PLATFORM_SUPPORTS_AWS_NATIVE_SDK",
                "LY_BUILD=398643",
                "_MT",
                "_DLL"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "path": [
                    "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/INCLUDE",
                    "C:/Program Files (x86)/Windows Kits/10/include/10.0.15063.0/ucrt",
                    "${workspaceRoot}/../TutorialSeries/Gem/Code/Source",
                    "${workspaceRoot}/../TutorialSeries/Gem/Code/Include",
                    "${workspaceRoot}/../Principia/Gem/Code/Source",
                    "${workspaceRoot}/../Principia/Gem/Code/Include",
                    "${workspaceRoot}/../Code/CryEngine/CryCommon",
                    "${workspaceRoot}/../Code/CryEngine/CryAction",
                    "${workspaceRoot}/../Code/Framework/AzGameFramework",
                    "${workspaceRoot}/../Gems/LmbrCentral/Code/include",
                    "${workspaceRoot}/../Gems/PhysicsWrapper/Code/include",
                    "${workspaceRoot}/../Code/Framework/AzFramework",
                    "${workspaceRoot}/../Code/Framework/GridMate",
                    "${workspaceRoot}/../Code/Framework/AzCore",
                    "${workspaceRoot}/../Code/Framework/AzTest",
                    "${workspaceRoot}/../Code/Framework/AzToolsFramework",
                    "${workspaceRoot}/../Code/SDKs/boost",
                    "${workspaceRoot}/../Code/SDKs/GoogleMock/include"
                ],
                "limitSymbolsToIncludedHeaders": false,
                "databaseFilename": "${workspaceRoot}/.vscode/.BROWSE.VC.DB"
            }
        }
    ],
    "version": 2
}

Again, TutorialSeries, Principia, and PhysicsWrapper are my gems/projects. You will need to remove them and add your own projects/gems.

Next we will set up the task.json

task.json:

{
    "version": "2.0.0",
    "options": {
        "cwd": "${cwd}/.."
    },
    "runner": "terminal",
    "echoCommand": true,
    "type": "shell",
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared"
    },
    "tasks": [
        {
            "taskName": "build all",
            "command": "lmbr_waf.bat build_win_x64_vs2015_debug -p all",
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build"
        },
        {
            "taskName": "build game",
            "command": "lmbr_waf.bat build_win_x64_vs2015_debug -p game",
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build"
        },
        {
            "taskName": "build configure",
            "command": "lmbr_waf.bat",
            "args": [
                "configure"
            ],
            "problemMatcher": [
                "$msCompile"
            ]
        },
        {
            "taskName": "build test",
            "command": "lmbr_waf.bat build_win_x64_vs2015_debug_test -p game",
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build"
        },
        {
            "taskName": "build test all",
            "command": "lmbr_waf.bat build_win_x64_vs2015_debug_test -p all",
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build"
        }
    ]
}

Anything with "group": "build" means you can do ctrl shift b, and it will give it to you as an option.

Anything else (like configure) you open the command palette (f1) and select run task, then select configure.

This is basically what Visual Studio is doing for you behind the scenes.

Setting up Debugging

So now we need to take care of the launch.json files. The way I set mine up is by having a global one in the VisualCode folder, and then specific ones in each folder I opened.

Here is the general one that will launch the editor.
VisualCode/.vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "editor",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/../Bin64vc140.Debug/Editor.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}/../Bin64vc140.Debug",
            "environment": [],
            "externalConsole": true
        }
    ]
}

Here is what a project launch.json would look like, in order to run the launcher and the unit/integration test.
TutorialSeries/.vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "launcher",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/../Bin64vc140.Debug/TutorialSeriesLauncher.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}/../Bin64vc140.Debug",
            "environment": [],
            "externalConsole": true
        },
        {
            "name": "test",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/../Bin64vc140.Debug.Test/AzTestRunner.exe",
            "args": [
                "Gem.TutorialSeries_7a17c44ce76744e1b646e6d8556372c8.v0.1.0.dll",
                "AzRunUnitTests",
                "--pause-on-completion"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}/../Bin64vc140.Debug.Test",
            "environment": [],
            "externalConsole": true
        },
        {
            "name": "integration",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/../Bin64vc140.Debug.Test/AzTestRunner.exe",
            "args": [
                "Gem.TutorialSeries_7a17c44ce76744e1b646e6d8556372c8.v0.1.0.dll",
                "AzRunIntegTests",
                "--pause-on-completion"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}/../Bin64vc140.Debug.Test",
            "environment": [],
            "externalConsole": true
        }
    ]
}

The GUID for your DLL can be found in either your Bin64vc140.Debug folder, or at the bottom of your TutorialSeries/Gem/Code/Source/TutorialSeriesModule.cpp equivalent file.

You own gems won’t have a launcher, but will still need their test set up to be ran and debugged.

PhysicsWrapper/.vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "test",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/../../Bin64vc140.Debug.Test/AzTestRunner.exe",
            "args": [
                "Gem.PhysicsWrapper.453b88cf44d041709924810814c70a70.v0.1.0.dll",
                "AzRunUnitTests",
                "--pause-on-completion"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}/../../Bin64vc140.Debug.Test",
            "environment": [],
            "externalConsole": true
        },
        {
            "name": "integration",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/../../Bin64vc140.Debug.Test/AzTestRunner.exe",
            "args": [
                "Gem.PhysicsWrapper.453b88cf44d041709924810814c70a70.v0.1.0.dll",
                "AzRunIntegTests",
                "--pause-on-completion"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}/../../Bin64vc140.Debug.Test",
            "environment": [],
            "externalConsole": true
        }
    ]
}

With these files in place, you should now see all your options in the debug part of visual code. It should look something like this:
tut_vscode_debug_options.png

Some Things About Visual Code

If you haven’t used vscode before, here’s a quick rundown.

On the left bar, you have:
1. Source with basic explorer functions (create file/folder, rename, etc)
2. Search everywhere
3. Source control (supports a few different types)
4. Debugger
5. Extensions – Shows installed ones until you type something in the search.

Most important command in vscode is to bring up the “command palette”. This is done by hitting F1 or Shift Control P.

Here are my personal settings. Open your user settings through the command palette or by hitting ctrl + comma. Here are mine.. you can change it however you’d like. Note that the settings JSON has intellisense/autocomplete.

{
    "git.confirmSync": false,
    "git.enableSmartCommit": true,
    "powermode.enabled": true,
    "powermode.enableShake": false,
    "powermode.explosionFrequency": 3,
    "powermode.maxExplosions": 10,
    "powermode.explosionSize": 5,
    "powermode.explosionOffset": 0.45,
    "window.zoomLevel": 0,
    "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
    "editor.renderWhitespace": "all",
    "files.trimTrailingWhitespace": true,
    "workbench.colorTheme": "Reloaded Dark [Default]",
    "files.autoSave": "afterDelay"
}

Navigating around visual code is similar to navigating VS with Resharper. Here are my most used keybindings:

  • Control p to do fuzzy searches for files
  • Control t to fuzzy search symbols (can take some time.)
  • Control e for history of files you’ve been to.
  • Control Shift v for your clipboard history (if you have the extension.)
  • Control Shift B for compiling
  • Control D to select multiple things with the same letters you’ve highlighted. (often you rename thing, I just select it, hold down control D to select them all, and then type the new name.)
  • Alt Shift Up or Down to duplicate the line up or down.
  • See File -> Preferences -> Keyboard Shortcuts for a complete list.

If you are adding a file, it is much easier now. Just add the files where you want them within vscode, then update the waf file. Then run the configure from the command palette (f1 -> run task -> configure, enter).

I also have a .clang-format file for the auto formatting feature. It goes into the VisualCode folder. Here is mine if you like having curlies on their own line, and namespaces indented. Also it left aligns public/private access types.

.clang-format:

UseTab: Never
IndentWidth: 4
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0
NamespaceIndentation: All
AccessModifierOffset: -4
PointerAlignment: Left

Conclusion

Visual Code with C++ is very new. Check out the issues on github if you have issues, or ask me.

3 thoughts on “Amazon Lumberyard with Visual Code

  1. Nice tutorial series, getting started with c/c++ with lumberyard has been a pain (and I have 20 years in c/c++) and your tutorial have helped out way more than any of the documentation I can find. Just a note, seems vs code has changed and the .code-workspace no longer supports the id tag and the folders array has changed to this

    {
    “folders”: [
    { “path”: “D:/projects/lumberyard_git/dev/VisualCode” },
    { “path”:”D:/projects/lumberyard_git/dev/Code”},
    { “path”:”D:/projects/lumberyard_git/dev/Gems”}
    ],

    }

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s