diff options
author | chai <chaifix@163.com> | 2018-12-06 13:12:29 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-12-06 13:12:29 +0800 |
commit | b3712ebdf148bd8d2d31e70734a4b7923f6038f8 (patch) | |
tree | c813d158030ee33b76d7ec23fa2deaa1eb0a4e36 /src | |
parent | 17d86218e25a6c889c24822da8d7b59967babd89 (diff) |
*remove create function
Diffstat (limited to 'src')
23 files changed, 255 insertions, 365 deletions
diff --git a/src/libjin/audio/SDL/je_sdl_source.cpp b/src/libjin/audio/SDL/je_sdl_source.cpp index d417bf7..90f8daa 100644 --- a/src/libjin/audio/SDL/je_sdl_source.cpp +++ b/src/libjin/audio/SDL/je_sdl_source.cpp @@ -24,7 +24,6 @@ namespace JinEngine namespace SDL { - #define BITS 8 typedef struct SDLSourceCommand @@ -74,14 +73,22 @@ namespace JinEngine //std::vector<SDLSource*> Manager::sources; Manager* Manager::manager = nullptr; - SDLSource* SDLSource::createSource(const char* file) + SDLSource::SDLSource() + { + memset(&status, 0, sizeof(status)); + memset(&raw, 0, sizeof(raw)); + status.volume = 1; + } + + SDLSource::SDLSource(const char* file) + : SDLSource() { std::ifstream fs; fs.open(file, std::ios::binary); if (!fs.is_open()) { fs.close(); - return nullptr; + return; } fs.seekg(0, std::ios::end); int size = fs.tellg(); @@ -90,38 +97,21 @@ namespace JinEngine memset(buffer, 0, size); fs.read(buffer, size); fs.close(); - SDLSource* source = createSource(buffer, size); + SDLSource(buffer, size); free(buffer); - return source; } - SDLSource* SDLSource::createSource(void* mem, size_t size) + SDLSource::SDLSource(void* mem, size_t size) + : SDLSource() { if (mem == nullptr) - return nullptr; - SDLSource* source = new SDLSource(); - try + return; + SourceType format = getType(mem, size); + switch (format) { - SourceType format = getType(mem, size); - switch (format) - { - case OGG: source->decode_ogg(mem, size); break; - case WAV: source->decode_wav(mem, size); break; - } + case OGG: decode_ogg(mem, size); break; + case WAV: decode_wav(mem, size); break; } - catch (SourceException& exp) - { - delete source; - return nullptr; - }; - return source; - } - - SDLSource::SDLSource() - { - memset(&status, 0, sizeof(status)); - memset(&raw, 0, sizeof(raw)); - status.volume = 1; } SDLSource::~SDLSource() diff --git a/src/libjin/audio/SDL/je_sdl_source.h b/src/libjin/audio/SDL/je_sdl_source.h index 07333ae..8a3309e 100644 --- a/src/libjin/audio/SDL/je_sdl_source.h +++ b/src/libjin/audio/SDL/je_sdl_source.h @@ -28,21 +28,19 @@ namespace JinEngine { public: /// - /// Create source from raw source data file. + /// Source constructor. + /// + SDLSource(); + + /// /// - /// @param file Audio source file. - /// @return Return source if create successful, otherwise return null. /// - static SDLSource* createSource(const char* file); + SDLSource(const char* file); /// - /// Create source from raw source data. - /// - /// @param mem Source data. - /// @param size Source data size. - /// @return Return source if create successful, otherwise return null. /// - static SDLSource* createSource(void* mem, size_t size); + /// + SDLSource(void* mem, size_t size); /// /// Source destructor. @@ -134,11 +132,6 @@ namespace JinEngine protected: /// - /// Source constructor. - /// - SDLSource(); - - /// /// Decode wav file. /// /// @param mem Wav file data. diff --git a/src/libjin/graphics/fonts/je_texture_font.cpp b/src/libjin/graphics/fonts/je_texture_font.cpp index 8facc34..9014509 100644 --- a/src/libjin/graphics/fonts/je_texture_font.cpp +++ b/src/libjin/graphics/fonts/je_texture_font.cpp @@ -17,28 +17,83 @@ namespace JinEngine namespace Fonts { - TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) + : Graphic(bitmap) + , Font(cellh) { - TextureFont* tf = new TextureFont(bitmap, codepoints, cellw, cellh); - return tf; + TextureGlyph glyph; + Vector2<int> count(bitmap->getWidth() / cellw, bitmap->getHeight() / cellh); + glyph.w = cellw; + glyph.h = cellh; + for (int y = 0; y < count.row; ++y) + { + glyph.y = y * cellh; + for (int x = 0; x < count.colum; ++x) + { + glyph.x = x * cellw; + if (x + y * count.colum >= codepoints.size()) + return; + glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[x + y * count.colum], glyph)); + } + } } - TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, int cellw, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) + : Graphic(bitmap) + , Font(cellh) { - TextureFont* tf = new TextureFont(bitmap, *codepoints, cellw, cellh); - return tf; + TextureGlyph glyph; + glyph.h = cellh; + int w = bitmap->getWidth(); + int h = bitmap->getHeight(); + int i = 0; + for (int y = 0; y < h; y += cellh) + { + glyph.y = y; + bool newc = false; + for (int x = 0; x <= w; ++x) + { + if (x == w && newc) + { + glyph.w = x - glyph.x; + if (i >= codepoints.size()) + return; + glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph)); + ++i; + newc = false; + break; + } + Color c = bitmap->getPixels()[x + y * w]; + if (!newc && c != mask) + { + glyph.x = x; + newc = true; + } + else if (newc && c == mask) + { + glyph.w = x - glyph.x; + if (i >= codepoints.size()) + return; + glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph)); + if (codepoints[i] == 't') + { + int a = 10; + } + ++i; + newc = false; + } + } + } } - TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh) + : TextureFont(bitmap, *text, mask, cellh) { - TextureFont* tf = new TextureFont(bitmap, codepoints, mask, cellh); - return tf; } - TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, Color mask, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh) + : TextureFont(bitmap, *text, cellw, cellh) { - TextureFont* tf = new TextureFont(bitmap, *codepoints, mask, cellh); - return tf; } TextureFont::~TextureFont() @@ -248,75 +303,6 @@ namespace JinEngine delete page; } - TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) - : Graphic(bitmap) - , Font(cellh) - { - TextureGlyph glyph; - Vector2<int> count(bitmap->getWidth() / cellw, bitmap->getHeight() / cellh); - glyph.w = cellw; - glyph.h = cellh; - for (int y = 0; y < count.row; ++y) - { - glyph.y = y * cellh; - for (int x = 0; x < count.colum; ++x) - { - glyph.x = x * cellw; - if (x + y * count.colum >= codepoints.size()) - return; - glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[x + y * count.colum], glyph)); - } - } - } - - TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) - : Graphic(bitmap) - , Font(cellh) - { - TextureGlyph glyph; - glyph.h = cellh; - int w = bitmap->getWidth(); - int h = bitmap->getHeight(); - int i = 0; - for (int y = 0; y < h; y += cellh) - { - glyph.y = y; - bool newc = false; - for (int x = 0; x <= w; ++x) - { - if (x == w && newc) - { - glyph.w = x - glyph.x; - if (i >= codepoints.size()) - return; - glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph)); - ++i; - newc = false; - break; - } - Color c = bitmap->getPixels()[x + y * w]; - if (!newc && c != mask) - { - glyph.x = x; - newc = true; - } - else if (newc && c == mask) - { - glyph.w = x - glyph.x; - if (i >= codepoints.size()) - return; - glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph)); - if (codepoints[i] == 't') - { - int a = 10; - } - ++i; - newc = false; - } - } - } - } - } } }
\ No newline at end of file diff --git a/src/libjin/graphics/fonts/je_texture_font.h b/src/libjin/graphics/fonts/je_texture_font.h index df8f956..a753cac 100644 --- a/src/libjin/graphics/fonts/je_texture_font.h +++ b/src/libjin/graphics/fonts/je_texture_font.h @@ -26,26 +26,25 @@ namespace JinEngine class TextureFont : public Font, public Graphic { public: - /// /// /// - static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh); + TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh); /// /// /// - static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh); + TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh); /// /// /// - static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh); + TextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh); /// /// /// - static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh); + TextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh); /// /// @@ -90,16 +89,6 @@ namespace JinEngine /// /// /// - TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh); - - /// - /// - /// - TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh); - - /// - /// - /// int getCharWidth(int c); /// diff --git a/src/libjin/graphics/fonts/je_ttf.cpp b/src/libjin/graphics/fonts/je_ttf.cpp index 3f664fa..fec8cd4 100644 --- a/src/libjin/graphics/fonts/je_ttf.cpp +++ b/src/libjin/graphics/fonts/je_ttf.cpp @@ -28,20 +28,6 @@ namespace JinEngine // TTFData ////////////////////////////////////////////////////////////////////////////////////////////////////// - TTFData* TTFData::createTTFData(const unsigned char* data, unsigned int size) - { - TTFData* ttf = nullptr; - try - { - ttf = new TTFData(data, size); - return ttf; - } - catch (...) - { - return nullptr; - } - } - TTFData::TTFData(const unsigned char* d, unsigned int s) { raw.size = s; diff --git a/src/libjin/graphics/fonts/je_ttf.h b/src/libjin/graphics/fonts/je_ttf.h index c2766b4..c5e2af5 100644 --- a/src/libjin/graphics/fonts/je_ttf.h +++ b/src/libjin/graphics/fonts/je_ttf.h @@ -37,11 +37,10 @@ namespace JinEngine class TTFData : public Object { public: - /// /// /// - static TTFData* createTTFData(const unsigned char* data, unsigned int size); + TTFData(const unsigned char* data, unsigned int size); /// /// @@ -93,11 +92,6 @@ namespace JinEngine /// /// /// - TTFData(const unsigned char* data, unsigned int size); - - /// - /// - /// stbtt_fontinfo info; /// diff --git a/src/libjin/graphics/je_bitmap.cpp b/src/libjin/graphics/je_bitmap.cpp index a6db55e..18e15a8 100644 --- a/src/libjin/graphics/je_bitmap.cpp +++ b/src/libjin/graphics/je_bitmap.cpp @@ -15,85 +15,86 @@ namespace JinEngine namespace Graphics { - Bitmap* Bitmap::createBitmap(const char* path) + Bitmap* Bitmap::clone() + { + Bitmap* b = new Bitmap(this); + return b; + } + + Bitmap::Bitmap() + : width(0) + , height(0) + , pixels(nullptr) + { + } + + Bitmap::Bitmap(unsigned w, unsigned h) + { + width = w; + height = h; + pixels = new Color[w*h]; + if (pixels == nullptr) + throw Exception("No enough memory."); + } + + Bitmap::Bitmap(const char* path) { AssetDatabase* ad = AssetDatabase::get(); - Buffer buffer; + Buffer buffer; ad->read(path, buffer); - return createBitmap(&buffer, buffer.size()); + new (this) Bitmap(&buffer, buffer.size()); } - Bitmap* Bitmap::createBitmap(const void* pixel, unsigned width, unsigned height) - { - Bitmap* bitmap = new Bitmap(width, height); - memcpy(bitmap->pixels, pixel, width*height * sizeof(Color)); - return bitmap; - } + Bitmap::Bitmap(const void* pix, unsigned w, unsigned h) + { + new (this) Bitmap(w, h); + memcpy(pixels, pix, w * h * sizeof(Color)); + } - Bitmap* Bitmap::createBitmap(const void* imgData, size_t size) - { - if (imgData == nullptr) - return nullptr; - int w, h; - void* data = stbi_load_from_memory((unsigned char *)imgData, size, &w, &h, NULL, STBI_rgb_alpha); + Bitmap::Bitmap(const void* imgData, size_t size) + { + if (imgData == nullptr) + return; + int w, h; + void* data = stbi_load_from_memory((unsigned char *)imgData, size, &w, &h, NULL, STBI_rgb_alpha); if (data == nullptr) { throw Exception("Could not create bitmap from image data."); - return nullptr; + return; } - Bitmap* bitmap = new Bitmap(); - bitmap->pixels = (Color*)data; - bitmap->width = w; - bitmap->height = h; - return bitmap; - } + new (this) Bitmap(); + pixels = (Color*)data; + width = w; + height = h; + } - Bitmap* Bitmap::createBitmap(int w, int h, Color color) - { - Bitmap* bitmap = new Bitmap(w, h); - if (color != Color::BLACK) - bitmap->setPixels(color); - return bitmap; - } + Bitmap::Bitmap(int w, int h, Color color) + { + new (this) Bitmap(w, h); + if (color != Color::BLACK) + setPixels(color); + } - Bitmap* Bitmap::createBitmap(int width, int height, std::function<Color(int, int, int, int)> drawer) + Bitmap::Bitmap(int w, int h, std::function<Color(int, int, int, int)> drawer) { - Bitmap* bitmap = new Bitmap(width, height); + new (this) Bitmap(w, h); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { Color c = drawer(width, height, x, y); - bitmap->setPixel(c, x, y); + setPixel(c, x, y); } } - return bitmap; } - /*static */ Bitmap* Bitmap::clone(const Bitmap* bitmap) - { - Bitmap* b = new Bitmap(); - int w = bitmap->getWidth(); - int h = bitmap->getHeight(); - b->resetPixels(bitmap->getPixels(), w, h); - return b; - } - - Bitmap::Bitmap() - : width(0) - , height(0) - , pixels(nullptr) - { - } - - Bitmap::Bitmap(unsigned w, unsigned h) - { - width = w; - height = h; - pixels = new Color[w*h]; - if (pixels == nullptr) - throw Exception("No enough memory."); - } + Bitmap::Bitmap(const Bitmap* bitmap) + { + new (this) Bitmap(); + int w = bitmap->getWidth(); + int h = bitmap->getHeight(); + resetPixels(bitmap->getPixels(), w, h); + } Bitmap::~Bitmap() { diff --git a/src/libjin/graphics/je_bitmap.h b/src/libjin/graphics/je_bitmap.h index e9c214e..c392a32 100644 --- a/src/libjin/graphics/je_bitmap.h +++ b/src/libjin/graphics/je_bitmap.h @@ -27,47 +27,35 @@ namespace JinEngine class Bitmap : public Object { public: - /// - /// Create bitmap from given file. - /// - /// @param path Path of image file. - /// @return Bitmap if create successful, otherwise retrun false. - /// - static Bitmap* createBitmap(const char* path); + /// + /// Constructor of bitmap. + /// + Bitmap(); /// - /// Create bitmap by pixels data. + /// Constructor of bitmap. /// - /// @param pixels Pixels data. /// @param width Width of bitmap. /// @param height Height of bitmap. - /// @return Return bitmap pointer if created, otherwise return null. /// - static Bitmap* createBitmap(const void* pixels, unsigned width, unsigned height); + Bitmap(unsigned w, unsigned h); - /// - /// Create bitmap from compressed image data. - /// - /// @param imgData Compressed image data. - /// @param size Size of image data. - /// @return Return bitmap pointer if created, otherwise return null. - /// - static Bitmap* createBitmap(const void* imgData, size_t size); + Bitmap(const char* path); + + Bitmap(const void* pixels, unsigned w, unsigned h); + + Bitmap(const void* imgData, size_t size); + + Bitmap(int w, int h, Color color); + + Bitmap(int w, int h, std::function<Color(int, int, int, int)> drawer); + + Bitmap(const Bitmap* bitmap); /// - /// Create bitmap with specific color and size. - /// - /// @param width Width of bitmap. - /// @param height Height of bitmap. - /// @param color Color of bitmap, black by default. - /// @return Return bitmap pointer if created, otherwise return null. + /// Destructor of bitmap /// - static Bitmap* createBitmap(int width, int height, Color color = Color::BLACK); - - /// - /// Create bitmap and set bitmap pixels with given drawer. - /// - static Bitmap* createBitmap(int width, int height, std::function<Color(int, int, int, int)> drawer); + virtual ~Bitmap(); /// /// Create bitmap with another one. @@ -75,12 +63,7 @@ namespace JinEngine /// @param bitmap Bitmap be cloned. /// @return Return bitmap pointer if created, otherwise return null. /// - static Bitmap* clone(const Bitmap* bitmap); - - /// - /// Destructor of bitmap - /// - virtual ~Bitmap(); + Bitmap* clone(); /// /// Directly bind pixels with given pixels data @@ -113,7 +96,7 @@ namespace JinEngine /// Set pixel with given color. /// /// @param color Color to be set. - /// @param x X value of pixel. + /// @param x X value of pixel. /// @param y Y value of pixel. /// void setPixel(const Color& color, int x, int y); @@ -169,19 +152,6 @@ namespace JinEngine inline Math::Vector2<int> getSize() const { return Math::Vector2<int>(width, height); } protected: - /// - /// Constructor of bitmap. - /// - Bitmap(); - - /// - /// Constructor of bitmap. - /// - /// @param width Width of bitmap. - /// @param height Height of bitmap. - /// - Bitmap(unsigned w, unsigned h); - Color * pixels; unsigned width, height; diff --git a/src/libjin/graphics/je_canvas.cpp b/src/libjin/graphics/je_canvas.cpp index 831544d..564121e 100644 --- a/src/libjin/graphics/je_canvas.cpp +++ b/src/libjin/graphics/je_canvas.cpp @@ -10,11 +10,6 @@ namespace JinEngine namespace Graphics { - Canvas* Canvas::createCanvas(int w, int h) - { - return new Canvas(w, h); - } - Canvas::Canvas(GLuint n) : fbo(n) { diff --git a/src/libjin/graphics/je_canvas.h b/src/libjin/graphics/je_canvas.h index e848e25..277e39d 100644 --- a/src/libjin/graphics/je_canvas.h +++ b/src/libjin/graphics/je_canvas.h @@ -16,12 +16,7 @@ namespace JinEngine /// class Canvas : public Graphic { - public: - /// - /// - /// - static Canvas* createCanvas(int w, int h); - + public: /// /// /// diff --git a/src/libjin/graphics/je_gl.cpp b/src/libjin/graphics/je_gl.cpp index a6abd34..453b4b4 100644 --- a/src/libjin/graphics/je_gl.cpp +++ b/src/libjin/graphics/je_gl.cpp @@ -24,7 +24,6 @@ namespace JinEngine : mBlendMode(BlendMode::NONE) { memset(&mColor, 0xff, sizeof(mColor)); - memset(&mBackColor, 0xff, sizeof(mBackColor)); // Set default modelview matrix. mModelViewMatrices.push_back(Matrix()); mModelViewMatrix.setIdentity(); @@ -36,16 +35,6 @@ namespace JinEngine { } - void OpenGL::pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) - { - memcpy(&mBackColor, &mColor, sizeof(mBackColor)); - mColor.r = r; - mColor.g = g; - mColor.b = b; - mColor.a = a; - glColor4ub(r, g, b, a); - } - void OpenGL::enable(GLenum cap) { glEnable(cap); @@ -63,7 +52,6 @@ namespace JinEngine void OpenGL::popColor() { - memcpy(&mColor, &mBackColor, sizeof(mBackColor)); glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); } @@ -358,9 +346,7 @@ namespace JinEngine void OpenGL::setFont(Fonts::Font* font) { if (font) - { mFont = font; - } } void OpenGL::unsetFont() diff --git a/src/libjin/graphics/je_gl.h b/src/libjin/graphics/je_gl.h index 0724426..de381f4 100644 --- a/src/libjin/graphics/je_gl.h +++ b/src/libjin/graphics/je_gl.h @@ -214,10 +214,6 @@ namespace JinEngine /// Color mColor; - //struct { GLubyte r, g, b, a; } mColor; // current draw color - //struct { GLubyte r, g, b, a; } mBackColor; // previous draw color - Color mBackColor; - /// /// /// diff --git a/src/libjin/graphics/je_image.cpp b/src/libjin/graphics/je_image.cpp index 2d8ceae..285cef2 100644 --- a/src/libjin/graphics/je_image.cpp +++ b/src/libjin/graphics/je_image.cpp @@ -11,27 +11,26 @@ namespace JinEngine using namespace Filesystem; - Image* Image::createImage(const void* imgData, size_t size) - { - if (imgData == nullptr) - return nullptr; - int w, h; - void* data = stbi_load_from_memory((uint8*)imgData, size, &w, &h, NULL, STBI_rgb_alpha); - if (data == nullptr) - return nullptr; - Image* image = new Image(); - image->pixels = (Color*)data; - image->width = w; - image->height = h; - return image; - } - - Image* Image::createImage(const char* path) + Image::Image(const char* path) { - AssetDatabase* fs = AssetDatabase::get(); + AssetDatabase* fs = AssetDatabase::get(); Buffer buffer; fs->read(path, buffer); - return createImage(&buffer, buffer.size()); + Image(&buffer, buffer.size()); + } + + Image::Image(const void* imgData, size_t size) + { + if (imgData == nullptr) + return; + int w, h; + void* data = stbi_load_from_memory((uint8*)imgData, size, &w, &h, NULL, STBI_rgb_alpha); + if (data == nullptr) + return; + Image(); + pixels = (Color*)data; + width = w; + height = h; } Image::Image() diff --git a/src/libjin/graphics/je_image.h b/src/libjin/graphics/je_image.h index 15baed3..432b875 100644 --- a/src/libjin/graphics/je_image.h +++ b/src/libjin/graphics/je_image.h @@ -17,21 +17,13 @@ namespace JinEngine { public: /// - /// Create image from image file. + /// Image constructor. /// - /// @param path Image path. - /// @return Image if created successfully, otherwise return null. - /// - static Image* createImage(const char* path); + Image(); - /// - /// Create image from image data. - /// - /// @param imgData Image data to create image. - /// @param size Size of image data. - /// @return Image if created successfully, otherwise return null. - /// - static Image* createImage(const void* imgData, size_t size); + Image(const char* path); + + Image(const void* imgData, size_t size); /// /// Image destructor. @@ -39,11 +31,6 @@ namespace JinEngine ~Image(); private: - /// - /// Image constructor. - /// - Image(); - // Disable setters inherited from Bitmap. void bind(Color* pixels, int w, int h); void resetPixels(const Color* pixels, int w, int h); diff --git a/src/libjin/graphics/je_sprite_sheet.h b/src/libjin/graphics/je_sprite_sheet.h index 8fee3f1..70aa5e3 100644 --- a/src/libjin/graphics/je_sprite_sheet.h +++ b/src/libjin/graphics/je_sprite_sheet.h @@ -15,6 +15,8 @@ namespace JinEngine class SpriteSheet { public: + SpriteSheet(const Graphic* graphic); + /// /// Create a new sprite in sheet. /// @@ -32,8 +34,6 @@ namespace JinEngine std::vector<Sprite*> createSprites(uint count, uint row, uint colum, uint w, uint h, float ox = 0, float oy = 0, uint offx = 0, uint offy = 0); - SpriteSheet(const Graphic* graphic); - private: const Graphic* const mGraphic; diff --git a/src/libjin/graphics/je_texture.cpp b/src/libjin/graphics/je_texture.cpp index 7f02c84..8d9bb0a 100644 --- a/src/libjin/graphics/je_texture.cpp +++ b/src/libjin/graphics/je_texture.cpp @@ -14,7 +14,7 @@ namespace JinEngine { namespace Graphics { - +/* Texture* Texture::createTexture(const char* path) { Bitmap* bitmap = Bitmap::createBitmap(path); @@ -28,6 +28,18 @@ namespace JinEngine Texture* tex = new Texture(bitmap); return tex; } +*/ + Texture::Texture() + : Graphic() + { + } + + Texture::Texture(const char* path) + { + Bitmap* bitmap = new Bitmap(path); + new (this) Texture(bitmap); + delete bitmap; + } Texture::Texture(const Bitmap* bitmap) : Graphic(bitmap) diff --git a/src/libjin/graphics/je_texture.h b/src/libjin/graphics/je_texture.h index 8e667f1..94e7a01 100644 --- a/src/libjin/graphics/je_texture.h +++ b/src/libjin/graphics/je_texture.h @@ -20,6 +20,7 @@ namespace JinEngine class Texture : public Graphic { public: +/* /// /// /// @@ -34,17 +35,27 @@ namespace JinEngine /// /// static Texture* createTexture(); +*/ /// /// /// - ~Texture(); + Texture(); + + /// + /// + /// + Texture(const char* path); - private: /// /// /// - Texture(const Bitmap* bitmap); + Texture(const Bitmap* bitmap); + + /// + /// + /// + ~Texture(); }; diff --git a/src/libjin/graphics/je_window.cpp b/src/libjin/graphics/je_window.cpp index 4c699aa..492fd22 100644 --- a/src/libjin/graphics/je_window.cpp +++ b/src/libjin/graphics/je_window.cpp @@ -71,7 +71,7 @@ namespace JinEngine // Set window icon try { - Bitmap* bitmap = Bitmap::createBitmap(icon); + Bitmap* bitmap = new Bitmap(icon); SDL_Surface *surface; Color* pixels = const_cast<Color*>(bitmap->getPixels()); uint w = bitmap->getWidth(), h = bitmap->getHeight(); @@ -89,7 +89,7 @@ namespace JinEngine // Default configuration. gl.setClearColor(0, 0, 0, 0xff); glClear(GL_COLOR_BUFFER_BIT); - gl.pushColor(0xff, 0xff, 0xff, 0xff); + gl.setColor(0xff, 0xff, 0xff, 0xff); gl.enable(GL_BLEND); gl.enable(GL_TEXTURE_2D); // Default blend function. diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp index f33adaf..017231a 100644 --- a/src/libjin/graphics/shaders/je_shader.cpp +++ b/src/libjin/graphics/shaders/je_shader.cpp @@ -53,7 +53,7 @@ namespace JinEngine // texture unit 0, and did not just forget to set the value. // const int DEFAULT_TEXTURE_UNIT = 0; - +/* Shader* Shader::createShader(const string& program) { Shader* shader = nullptr; @@ -67,7 +67,7 @@ namespace JinEngine } return shader; } - +*/ Shader::Shader(const string& program) : mCurrentTextureUnit(DEFAULT_TEXTURE_UNIT) { diff --git a/src/libjin/graphics/shaders/je_shader.h b/src/libjin/graphics/shaders/je_shader.h index 2f53ab0..a30413c 100644 --- a/src/libjin/graphics/shaders/je_shader.h +++ b/src/libjin/graphics/shaders/je_shader.h @@ -37,7 +37,12 @@ namespace JinEngine /// /// @param source The shader source code. /// - static Shader* createShader(const std::string& source); + //static Shader* createShader(const std::string& source); + + /// + /// Shader constructor. + /// + Shader(const std::string& program); /// /// Destructor of shader. @@ -156,11 +161,6 @@ namespace JinEngine GLint claimTextureUnit(const std::string& name); /// - /// Shader constructor. - /// - Shader(const std::string& program); - - /// /// Compile JSL program into GLSL source. /// /// @param program JSL source code. diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp index 2935e1a..47ed078 100644 --- a/src/lua/modules/audio/je_lua_audio.cpp +++ b/src/lua/modules/audio/je_lua_audio.cpp @@ -90,7 +90,7 @@ namespace JinEngine luax_pushnil(L); return 1; } - Source* src = Source::createSource((void*)&b, b.size()); + Source* src = new SDLSource((void*)&b, b.size()); if (src == nullptr) { error(L, "Failed to decode source file %s", f); diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp index 26908e6..1733529 100644 --- a/src/lua/modules/graphics/je_lua_bitmap.cpp +++ b/src/lua/modules/graphics/je_lua_bitmap.cpp @@ -89,7 +89,7 @@ namespace JinEngine { SharedBitmap shared = checkBitmap(L); Bitmap* bitmap = shared.getObject(); - Bitmap* b = Bitmap::clone(bitmap); + Bitmap* b = bitmap->clone(); LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Bitmap, new Shared<Bitmap>(b, Jin_Lua_Bitmap)); return 1; } diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index 7175309..05231c2 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -69,8 +69,8 @@ namespace JinEngine } /* load default font */ - Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap)); - TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight()); + Bitmap* bitmap = new Bitmap(default_font_bitmap, sizeof(default_font_bitmap)); + TextureFont* tf = new TextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight()); delete bitmap; context.defaultFont = tf; gl.setFont(tf); @@ -137,7 +137,7 @@ namespace JinEngine { int w = luax_checkinteger(L, 1); int h = luax_checkinteger(L, 2); - bitmap = Bitmap::createBitmap(w, h); + bitmap = new Bitmap(w, h); } else if (luax_gettop(L) == 3) { @@ -149,7 +149,7 @@ namespace JinEngine unsigned int g = luax_rawgetnumber(L, 3, 2); unsigned int b = luax_rawgetnumber(L, 3, 3); unsigned int a = luax_rawgetnumber(L, 3, 4); - bitmap = Bitmap::createBitmap(w, h, Color(r, g, b, a)); + bitmap = new Bitmap(w, h, Color(r, g, b, a)); } else if (luax_isfunction(L, 3)) { @@ -173,7 +173,7 @@ namespace JinEngine luax_pop(L, 1); return c; }; - bitmap = Bitmap::createBitmap(w, h, drawer); + bitmap = new Bitmap(w, h, drawer); } else { @@ -198,7 +198,7 @@ namespace JinEngine luax_pushnil(L); return 1; } - bitmap = Bitmap::createBitmap(&b, b.size()); + bitmap = new Bitmap(&b, b.size()); if (bitmap == nullptr) { error(L, "Failed to decode image file %s", f); @@ -219,12 +219,12 @@ namespace JinEngine LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Bitmap); Shared<Bitmap>& refBitmap = p->getShared<Bitmap>(); Bitmap* bitmap = refBitmap.getObject(); - texture = Texture::createTexture(bitmap); + texture = new Texture(bitmap); } else if (luax_isstring(L, 1)) { const char* path = luax_checkstring(L, 1); - texture = Texture::createTexture(path); + texture = new Texture(path); } LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Texture, new Shared<Texture>(texture, Jin_Lua_Texture)); return 1; @@ -233,7 +233,7 @@ namespace JinEngine LUA_IMPLEMENT int l_newShader(lua_State* L) { const char* program = luax_checkstring(L, 1); - Shader* jsl = Shader::createShader(program); + Shader* jsl = new Shader(program); if (jsl == nullptr) { error(L, "Failed to compile shader"); @@ -256,7 +256,7 @@ namespace JinEngine } Buffer b; fs->read(path, b); - Shader* jsl = Shader::createShader((char*)&b); + Shader* jsl = new Shader((char*)&b); if (jsl == nullptr) { error(L, "Failed to compile shader"); @@ -271,7 +271,7 @@ namespace JinEngine { int w = luax_checknumber(L, 1); int h = luax_checknumber(L, 2); - Canvas* cvs = Canvas::createCanvas(w, h); + Canvas* cvs = new Canvas(w, h); LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Canvas, new Shared<Canvas>(cvs, Jin_Lua_Canvas)); return 1; } @@ -681,7 +681,7 @@ namespace JinEngine } Buffer b; fs->read(path, b); - fd = TTFData::createTTFData(&b, b.size()); + fd = new TTFData(&b, b.size()); } LuaObject* luaObj = luax_newinstance(L, Jin_Lua_TTFData, new Shared<TTFData>(fd, Jin_Lua_TTFData)); return 1; @@ -869,12 +869,12 @@ namespace JinEngine unsigned int g = luax_rawgetnumber(L, 3, 2); unsigned int b = luax_rawgetnumber(L, 3, 3); unsigned int a = luax_rawgetnumber(L, 3, 4); - textureFont = TextureFont::createTextureFont(bitmap, *text, Color(r, g, b, a), cellh); + textureFont = new TextureFont(bitmap, *text, Color(r, g, b, a), cellh); } else if (luax_isnumber(L, 3)) { float cellw = luax_checknumber(L, 3); - textureFont = TextureFont::createTextureFont(bitmap, *text, cellw, cellh); + textureFont = new TextureFont(bitmap, *text, cellw, cellh); } else { |