エンジンのグラフィックスモジュールを記述しようとしています。つまり、コードのこの部分は、画像、フォントなどをロードして画面に描画するためのインターフェースのみを提供します。また、私が使用しているライブラリ(この場合はSDL)のラッパーでもあります。
これがImage
、Font
とGraphicsRenderer
クラスのインターフェースです。私が正しい方向に進んでいるかどうか教えてください。
画像
class Image
{
public:
Image();
Image(const Image& other);
Image(const char* file);
~Image();
bool load(const char* file);
void free();
bool isLoaded() const;
Image& operator=(const Image& other);
private:
friend class GraphicsRenderer;
void* data_;
};
フォント
class Font
{
public:
Font();
Font(const Font& other);
Font(const char* file, int ptsize);
~Font();
void load(const char* file, int ptsize);
void free();
bool isLoaded() const;
Font& operator=(const Font& other);
private:
friend class GraphicsRenderer;
void* data_;
};
GrapphicsRenderer
class GraphicsRenderer
{
public:
static GraphicsRenderer* Instance();
void blitImage(const Image& img, int x, int y);
void blitText(const char* string, const Font& font, int x, int y);
void render();
protected:
GraphicsRenderer();
GraphicsRenderer(const GraphicsRenderer& other);
GraphicsRenderer& operator=(const GraphicsRenderer& other);
~GraphicsRenderer();
private:
void* screen_;
bool initialize();
void finalize();
};
編集:コードの一部の変更と詳細。
ここでのいくつかの議論に従って、私はの使用void*
を次のようなものに置き換えることにしました:
class Image
{
private:
struct ImageData;
std::shared_ptr<ImageData> data_;
};
(もちろん、Font
クラスでも同じことをします。)
また、これらは私の最後の完全なクラスではないことにも触れておきます。ここでは、基本的な機能(読み込みとレンダリング)のみを示します。追加する必要があると思われる機能(画像の回転、傾斜、スケーリングなど)を伝える代わりに、すでに持っているものを確認することに集中してください。私はできる限り自分の選択を守ろうとします。できない場合は私のアプローチを変えます。