Lua スクリプトから C++ のゲーム エンジンにテクスチャをロードしようとしています。
エンジンは「ResourceHolder」と呼ばれるクラスを使用し、列挙型は「ResourceIdenifiers」と呼ばれるクラスからのものです。
私のゲーム シーンは、テクスチャとフォントの両方 (およびその他の必要なもの) に対して独自の ResourceHolder を作成します。したがって、Textures::ID (列挙型) と Fonts::ID の名前空間があります。
したがって、TextureHolder オブジェクト「mTextures」を作成するだけです。
TextureHolder mTextures;
次に、次のように 1 行で非常に簡単にテクスチャをロードします。
mTextures.load(Textures::Airplane2, "../GFX/Airplane2.png");
問題は、lua.script ファイルに次のようなものを含める予定であるにもかかわらず、Lua でこれらの列挙型を使用できないことです。
allTextures
{
--Airplanes
["Airplane1"] = "../GFX/Airplane1.png",
["Airplane2"] = "../GFX/Airplane2.png",
--Or something like this instead
["Textures::Airplane3"] = "../GFX/Airplane3.png"
}
Lua スクリプトがこれらの列挙型を処理できるようにする最も簡単な方法は何ですか?
ResourceIdentifier と ResourceHolder のクラスは次のとおりです。
ResourceIdentifier.h
#ifndef RESOURCEIDENTIFIERS_H
#define RESOURCEIDENTIFIERS_H
// Forward declaration of SFML classes
namespace sf
{
class Texture;
class Font;
}
namespace Textures
{
enum ID
{
//Airplanes
Airplane1,
Airplane2,
Airplane3,
Background1,
Background2,
};
}
namespace Fonts
{
enum ID
{
Main,
};
}
// Forward declaration and a few type definitions
template <typename Resource, typename Identifier>
class ResourceHolder;
typedef ResourceHolder<sf::Texture, Textures::ID> TextureHolder;
typedef ResourceHolder<sf::Font, Fonts::ID> FontHolder;
#endif // RESOURCEIDENTIFIERS_H
ResourceHolder.h (関連性が低い)
#ifndef RESOURCEHOLDER_H
#define RESOURCEHOLDER_H
#include <map>
#include <string>
#include <memory>
#include <stdexcept>
#include <cassert>
#include <SFML/Graphics/Image.hpp>
template <typename Resource, typename Identifier>
//This class stores Identifier so they can be accessed.
class ResourceHolder
{
public:
//This creates loads the texture from the filename, gives it an ID, and stores it in the std::map container mTextureMap.
void load(Identifier id, const std::string& filename);
void loadImage(Identifier id, const sf::Image& image);
template <typename Parameter>
void load(Identifier id, const std::string& filename, const Parameter& secondParam);
//This gets the texture from the std::map container, so it can be used. It gets the Resource based on the texture's ID (name).
Resource& get(Identifier id);
const Resource& get(Identifier id) const;
//^SFML book - Chapter 2 - "Accessing the Identifier" ??? For when you dont want to allow editing of the Texture???
private:
//A map stores all of the Identifier. The std::map< (1 parameter) 'Name of Resource', (2 parameter) a unique pointer of the Resource).
std::map<Identifier, std::unique_ptr<Resource> > mResourceMap;
};
#include "ResourceHolder.inl"
#endif // RESOURCEHOLDER_H