[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.4.2 Loading The Map

Here we add the code to load a map. In this example we will load the `flarge' map which is included with Crystal Space.

In the second tutorial we already mentioned VFS (see section 7.2 Virtual File System (VFS)). This is important in this case too since we are going to load the map from the virtual filesystem. To do this we first add the following code right before the creation of the view:

 
bool Simple::Initialize (int argc, const char* const argv[])
{
  ...

  // Set VFS current directory to the level we want to load.
  iVFS* VFS = CS_QUERY_REGISTRY (object_reg, iVFS);
  VFS->ChDir ("/lev/flarge");
  VFS->DecRef ();
  // Load the level file which is called 'world'.
  if (!loader->LoadMapFile ("world"))
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.simple",
    	"Couldn't load level!");
    return false;
  }
  engine->Prepare ();

  ...

This code will first use iVFS::ChDir() to set the current directory in the virtual file system to `/lev/flarge'. In the case of `flarge' this MOUNT POINT is already created in the config file `vfs.cfg'. If this is not the case for your own levels you can either modify `vfs.cfg' or else call iVFS::Mount() to map a physical file path (can be a ZIP archive file as well) to a virtual directory.

The call to iLoader::LoadMapFile() will take the given filename (in this case `world') and open it from the current VFS directory. Then it will parse that file and create the geometry which is specified there.

If this is succesful then you must call iEngine::Prepare() to make sure that all lightmaps are correctly loaded from the cache and other necessary setup work is done (i.e. textures are registered and so on).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated using texi2html