4.2.3.2 マップのロード


4.2.3.2 マップのロード

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

ここでは、マップを読み込むためのコードを追加します。この例では、Crystal Spaceに含まれる`flarge`マップを読み込みます。

In the second tutorial we already mentioned VFS (see section 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 new LoadMap?() routine just before the OnInitialize?() function:

第2のチュートリアルの中で、VFSについてすでに述べています(see section Virtual File System(VFS))。この例では、仮想ファイルシステムからマップを読み込むことも、重要なことです。これをすることで、はじめてOnInitialize?()機能の後に、新しいLoadMap?()手順を追加します。

bool Simple::LoadMap ()
{
 // Set VFS current directory to the level we want to load.
 csRef<iVFS> VFS (csQueryRegistry<iVFS> (object_reg));
 VFS->ChDir ("/lev/flarge");
 // Load the level file which is called 'world'.
 if (!loader->LoadMapFile ("world"))
   ReportError("Error couldn't load level!");
 return true;
}

This code first uses iVFS::ChDir?() to set the current directory in the virtual file system to `/lev/flarge'. In the case of `flarge' this mount point exists already in the configuration file `vfs.cfg'. If this is not the case for your own levels, you can either modify `vfs.cfg', provide your own `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.

このコードで、仮想ファイルシステムのカレントディレクトリに`lev/flarge/`を設定するために、iVFS::ChDir?()を使用します。`flarge`の場合、このマウント位置は、設定ファイル`vfs.cfg`の中にすでに存在します。あなた自身の階層のために、`vfs.cfg`に設定が存在しない場合、あなたには3つの変更方法があります。

  1. `vsf.cfg`を変更します
  2. 自身で`vsf.cfg`を用意します
  3. 仮想ディレクトリに物理ファイルパスを位置づけるために、iVFS::Mount()を呼びます(Zip アーカイブファイルも同様にできます)

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.

iLoader::LoadMapFile?()は、与えられたファイル名を第1引数に指定し(この例では`world`です)、現在のVFSディレクトリからファイルを開きます。そして、ファイルを構文解析し、指定された形状を作成します。

If loading is successful, 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). This is demonstrated in the code below, which you add to the Application() method, following the SetRectangle?() invocation. We also add code to initialize collision detection for geometry in the map which was just loaded.

読み込み成功後、あなたは、以下2つのことを確認するために、iEngine::Prepare()を呼ばなければなりません。

  1. すべてのライトマップがキャッシュから正確に読み込まれているか
  2. 他の必要なセットアップが完了したか(例えば、テクスチャが登録されたか等)

これは下のコードで実際に実行しています。それは、Application()メソッド内の、 SetRectangle?()の実行の次の行に追加します。読み込んだマップの形状のための衝突探知の初期化のコードも追加します。

bool Simple::Application ()
{
 ...
 view->SetRectangle (0, 0, g2d->GetWidth (), g2d->GetHeight ());

 // Here we load our world from a map file.
 if (!LoadMap ()) return false;

 // Initialize collision objects for all loaded objects.
 csColliderHelper::InitializeCollisionWrappers (cdsys, engine);

 // Let the engine prepare all lightmaps for use and also free all
 // images that were loaded for the texture manager.
 engine->Prepare ();

 Run();
 ...
}

So, we now have geometry loaded into the world, but we haven't set the current sector or the camera's position in the world. Often, maps contain information specifying where the camera should be placed when the map is first loaded, so we will use this information if present. This is the topic of the next section.

現在、私たちは、ワールド内に読み込んだ形状を持っています。しかし、現在のセクタやワールド内のカメラ位置をセットしていません。しばしば、マップがはじめて読み込まれた時のカメラの配置情報も、マップが持っています。だから、カメラ配置情報がある時は、この情報を使用します。これは次の章の話題です。

最新の20件

2007-02-18 2007-02-12 2007-01-31 2007-02-12 2007-01-14 2007-01-21 2007-02-12 2007-02-11 2007-01-15 2007-01-14 2007-02-12 2007-02-11 2007-02-01 2007-01-21 2007-01-19 2007-02-12 2007-01-19 2009-08-27 2007-01-10

今日の10件

  • counter: 98
  • today: 1
  • yesterday: 0
  • online: 1