官术网_书友最值得收藏!

Configuring Visual Studio 2008 to work with Panda3D

The scripting-centric architecture of the Panda3D divides development into two sides. One of them is the application code written in Python that is created by game programmers to control the gameplay behavior of their games. On the opposite side we can find the engine modules, which are written in C++ and compiled to native modules. At runtime, the Python interpreter found that the core of Panda3D loads these modules and lets us make calls into them to control the engine and the game running on it.

This programming model combines the best of both of these programming worlds. While the performance critical parts are implemented in C++, gameplay programmers do not know any of the advanced stuff going on under the hood to get things done. Instead, they are able to use Python, an expressive and easy to learn programming language, for using Panda3D's great features. This also allows the engine developers to work on the internals of Panda3D while gameplay programmers are able to concentrate on creating interesting games.

While this split between application and gameplay code works really well, nothing keeps us from using the Panda3D programming libraries and writing application side code in C++. There' s nothing wrong with coding our games in Python, and in general it is the path to follow with Panda3D. But the possibility to use C++ is there, so we shouldn't omit discussing this topic.

In this recipe we will configure Visual Studio 2008 for compiling Panda3D C++ projects on Windows. Panda3D is a cross-platform game engine and other compilers like gcc and alternative IDEs like KDevelop might as well be used for writing C++ programs that link to the Panda3D libraries but within the context of this book, we will be looking at how things are working on the Windows platform.

Getting ready

This recipe assumes that Visual Studio 2008 is already installed on your system. If not, you can download Visual C++ 2008 Express Edition from www.microsoft.com/express/Downloads/ for free. Some restrictions apply to this free edition, but all recipes in this book are tested to work with this version of Visual Studio.

Note

Although technically very similar, the Express and full editions of Visual Studio do differ in several ways. Some menus, options, and functions of the full versions are not available in the free Express edition. So if you are looking for help online you should always clearly state which version you are using.

How to do it...

The following tasks will help you to configure Visual Studio 2008 for developing Panda3D projects:

  1. In a text editor of your choice, create a new file and paste the following code:
    <?xml version="1.0" encoding="Windows-1252"?>
    <VisualStudioPropertySheet
        ProjectType="Visual C++"
        Version="8.00"
        Name="PandaSettings"
        >
        <Tool
            Name="VCCLCompilerTool"
            AdditionalIncludeDirectories="&quot;C:\Panda3D-1.7.0\python\include&quot;;&quot;C:\Panda3D-1.7.0\include&quot;"
        />
        <Tool
            Name="VCLinkerTool"
            AdditionalDependencies="libp3framework.lib libpanda.lib libpandafx.lib libpandaexpress.lib libp3dtool.lib libp3dtoolconfig.lib libp3pystub.lib libp3direct.lib"
            AdditionalLibraryDirectories="&quot;C:\Panda3D-1.7.0\python\libs&quot;;&quot;C:\Panda3D-1.7.0\lib&quot;"
        />
    </VisualStudioPropertySheet>
  2. Save it as PandaSettings.vsprops in a directory of your choice.
  3. Start Visual Studio 2008 or Visual C++ 2008 Express and create a new C++ project.
  4. Open the Property Manager, which is located in the same pane as the Solution Explorer and the Class View by default. If you can't find it this way, click View | Property Manager in the main menu.
  5. Right-click the item Release | Win32 and select Add Existing Property Sheet... from the popup menu.
  6. Locate and select the PandaSettings.vsprops file.

How it works...

In this recipe we set all the options for using Panda3D using a feature of Visual Studio called Property Sheets, which allow you to configure each build target of your project independently and in a reusable way.

Property Sheet settings are stored using XML, as you can see in the previous sample code. Let's have a look at the data stored in PandaSettings.vsprops:

Following the XML header and the opening tag of the property sheet, we can see two <Tool/> tags, the first of which is adding the required include paths to the header search paths. The second <Tool/> tag instructs the linker to use the listed library files when it is generating the executable, as well as where it will need to look for these files.

There's more...

You might have noticed that we only configured the release target in this recipe. The reason for this is that the recipe is aimed at the precompiled Panda3D SDK, which only includes the files needed to produce release builds.

Note

If you want to create debug builds you will definitely need to compile Panda3D yourself and configure your debug target in the way shown in this recipe (but don't forget to modify the search paths accordingly!).

Also, you don't have to use Property Sheets to configure include directories and linked libraries. You may also right-click the project node in the project explorer, click Properties and then click Configuration Properties | Properties | C++ in the tree of configuration categories to then fill in the include directories in the Additional Include Directories field in the right pane of the window.

To configure the linker, choose Configuration Properties | Properties | Linker in the same window as previously described and fill in the library file names into the Additional Dependencies and Additional Library Directories fields.

主站蜘蛛池模板: 乌拉特后旗| 诸城市| 靖江市| 亳州市| 乌拉特后旗| 博爱县| 苗栗县| 舞钢市| 渝中区| 西藏| 云和县| 新乡县| 驻马店市| 云安县| 文昌市| 永州市| 张北县| 凌海市| 馆陶县| 霍山县| 穆棱市| 新野县| 太和县| 梅河口市| 乾安县| 蚌埠市| 五大连池市| 岱山县| 淄博市| 罗源县| 呼和浩特市| 陆河县| 宁武县| 合川市| 杂多县| 长泰县| 湘西| 石棉县| 永清县| 宁化县| 韶关市|