Building a Content Pipeline Extension - Part 2/8

Parts > 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

About the Projects We're Using

To try to explain what's going on in this first step, it will be very important to understand the overall structure of the projects that we're going to be creating.

There are going to be four projects that we're working with, as we do this. Two of these, we've used before, and you're probably familiar with, by now. The other two are new, and they're a part of our custom content pipeline extension.

Let's discuss each of these four projects in a bit of detail, and then discuss how they tie together.

Main Game Project

This project is the same type of project that you have used in all of the previous tutorials, and we will create it in the same way and just link it to the other libraries. The stuff we do in this class will be pretty easy since it will be very similar to what we have done before.

Main Game Content Project

As a part of the main game, there's a content project that we've also used in the past (it's where we've put all of our content in the past). Again, we've used this before, so there's nothing new with it, except linking it to the other two projects.

Game Library

The first project we will create will be a library for our game. A library is a collection of methods, classes, or other code, just like any other project. The difference is that the library has no entry point - you can't execute a library. In fact, later on, when we compile the library project, you can browse through the project's directory and find where the library was compiled to. If you did this, you would discover that the project was compiled into a .dll file (short for "Dynamic-Link Library") rather than a .exe file. While you can't run this on its own, other programs can access the stuff inside it. This is exactly what we want because both of the other projects will need to access it. Inside of the game library project, we will add the class for our level data, and if the information in your level was especially complicated, you could put multiple classes in here as well. In fact, later, we will put the content reader in this project as well.

Content Pipeline Extension Library

The second project we will work on is the content pipeline extension library. This project is a library, like before, but it will also be linked in with the necessary stuff to work with the content pipeline. We will put all of the stuff related to the content pipeline in this project, with the exception of the content reader, which will go in the game library class. Because this project/library is linked to the content pipeline, it won't really function correctly on a computer that doesn't have the necessary content pipeline stuff, so you won't need to redistribute the stuff in this project.

How they Tie Together

So far, we've used just the two projects (the main game project, and the main game content project), and they've already been connected together as needed. With the addition of two new projects, we'll also need to connect them with the original two, and to each other as well, in just the right way, as shown in the image below.


The stuff in red already exists when we create our game. We're going to be adding the two green projects, and adding the links between them to make everything work out correctly. For starters, since the LevelLibrary project has the core Level classes, our main game and the new LevelContentPipelineExtension project will both have to reference it. Additionally, the main content project will also need to know about the LevelContentPipelineExtension project, so that it can push stuff through the new content pipeline extension. We'll discuss the specifics of how to link these projects in more detail in a minute.

Creating the Projects

OK, now that we've outlined what projects we will need, let's go ahead and get started. We are going to start with a normal project, but if you are trying to add a content pipeline extension to an existing game of yours, feel free to skip this step and jump down a couple of paragraphs to where we create the other projects.

Create a new project, like we have done before, using the Windows Game (4.0) template. You can call yours whatever you want, but I've called mine "ContentPipelineExtension". In this tutorial, we will be working with the Solution Explorer (located by default on the right side of XNA Game Studio), and making changes to it, so below is a screenshot of what my Solution Explorer looks like after this step:


The next step is to create the game library. This is extremely easy to do. In the Solution Explorer, near the very top, find the root node, which in mine currently says "Solution 'ContentPipelineExtension' (2 projects)". Right-click on this node and choose Add > New Project from the menu that pops up. This will bring up a wizard that will give you options in creating the game library project. In the Templates box, be sure to choose the Windows Game Library (4.0) template and give it a name. I've called mine "LevelLibrary". Once you've done this, press OK to create the game library project.


This will create the project for you, and additionally, create a new class for you called Class1.cs inside of the project. I think the XNA people thought this would be helpful, but we're going to just delete it. Do this by right-clicking on the file Class1.cs in your Solution Explorer and choosing Delete. It will ask you to confirm that you really want to delete the file, but just go ahead and tell it to remove it. In the next section, we will create our own class. My Solution Explorer now looks like this:


We are now ready to create the third project, which is the actual content pipeline extension library. We will follow a similar process to when we created the game library. Go to the Solution Explorer and right-click on the Solution node, which should now say something like "Solution <your project name>' (3 projects)". Choose Add > New Project from the menu. The project setup dialog will appear again. This time, use the Content Pipeline Extension Library (4.0) template and give it a name. I've called mine "LevelContentPipelineExtension". When you're ready, press the OK button to create the project.


Once again, this creates a file that we don't really need, so like before, remove the file "ContentProcessor1.cs" like before by right-clicking on the file and choosing Delete. Your Solution Explorer should now look like the image below:


Linking the Projects

The final thing that we need to do is link the projects together so that they know about each other. There are three parts to this. First, the content pipeline extension project needs to know about the game library project, because it will be using it to load the level information. Second, the main game project will also need to know about the game library project. Finally, the main game content project will need to know about the content pipeline extension project. Linking these projects together isn't actually too hard to do.

If you look in the Solution Explorer, you will find that each project has an item called References. We will link the projects by adding new references under the appropriate References node, as shown in the image below:


To add a reference, right-click on the correct References item, and choose Add Reference from the menu item that appears. This will bring up a dialog titled "Add References". Click on the Projects tab and find the correct reference and choose OK. Notice that for the third reference, we need the References item that is under the Content item to have a reference to the content pipeline extension, not the References item for the whole project. With these three references, you should be ready to proceed to the next part of the tutorial!

Continue on to part 3

Parts > 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

Troubleshooting.png Having problems with this tutorial? Try the troubleshooting page!