diff --git a/src/CSFML/Graphics/CircleShape.cpp b/src/CSFML/Graphics/CircleShape.cpp index f70c307..6a0b8cc 100644 --- a/src/CSFML/Graphics/CircleShape.cpp +++ b/src/CSFML/Graphics/CircleShape.cpp @@ -170,7 +170,7 @@ sfTransform sfCircleShape_getInverseTransform(const sfCircleShape* shape) void sfCircleShape_setTexture(sfCircleShape* shape, const sfTexture* texture, bool resetRect) { assert(shape); - shape->setTexture(texture ? texture->This : nullptr, resetRect); + shape->setTexture(texture, resetRect); shape->Texture = texture; } diff --git a/src/CSFML/Graphics/ConvertRenderStates.hpp b/src/CSFML/Graphics/ConvertRenderStates.hpp index 1937ca1..61f4aba 100644 --- a/src/CSFML/Graphics/ConvertRenderStates.hpp +++ b/src/CSFML/Graphics/ConvertRenderStates.hpp @@ -51,7 +51,7 @@ renderStates.blendMode.alphaDstFactor = static_cast(states->blendMode.alphaDstFactor); renderStates.blendMode.alphaEquation = static_cast(states->blendMode.alphaEquation); renderStates.transform = convertTransform(states->transform); - renderStates.texture = states->texture ? states->texture->This : nullptr; + renderStates.texture = states->texture; renderStates.shader = states->shader; return renderStates; } diff --git a/src/CSFML/Graphics/ConvexShape.cpp b/src/CSFML/Graphics/ConvexShape.cpp index 449fac9..b18dc14 100644 --- a/src/CSFML/Graphics/ConvexShape.cpp +++ b/src/CSFML/Graphics/ConvexShape.cpp @@ -167,7 +167,7 @@ sfTransform sfConvexShape_getInverseTransform(const sfConvexShape* shape) void sfConvexShape_setTexture(sfConvexShape* shape, const sfTexture* texture, bool resetRect) { assert(shape); - shape->setTexture(texture ? texture->This : nullptr, resetRect); + shape->setTexture(texture, resetRect); shape->Texture = texture; } diff --git a/src/CSFML/Graphics/Font.cpp b/src/CSFML/Graphics/Font.cpp index 2ac5ba1..afb44c7 100644 --- a/src/CSFML/Graphics/Font.cpp +++ b/src/CSFML/Graphics/Font.cpp @@ -152,7 +152,7 @@ const sfTexture* sfFont_getTexture(sfFont* font, unsigned int characterSize) { assert(font); - *font->Textures[characterSize].This = font->getTexture(characterSize); + font->Textures[characterSize] = sfTexture{font->getTexture(characterSize)}; return &font->Textures[characterSize]; } diff --git a/src/CSFML/Graphics/RectangleShape.cpp b/src/CSFML/Graphics/RectangleShape.cpp index 4a2747b..2a6bcb4 100644 --- a/src/CSFML/Graphics/RectangleShape.cpp +++ b/src/CSFML/Graphics/RectangleShape.cpp @@ -167,7 +167,7 @@ sfTransform sfRectangleShape_getInverseTransform(const sfRectangleShape* shape) void sfRectangleShape_setTexture(sfRectangleShape* shape, const sfTexture* texture, bool resetRect) { assert(shape); - shape->setTexture(texture ? texture->This : nullptr, resetRect); + shape->setTexture(texture, resetRect); shape->Texture = texture; } diff --git a/src/CSFML/Graphics/RenderTexture.cpp b/src/CSFML/Graphics/RenderTexture.cpp index 8aacd8a..919ebdb 100644 --- a/src/CSFML/Graphics/RenderTexture.cpp +++ b/src/CSFML/Graphics/RenderTexture.cpp @@ -54,7 +54,7 @@ sfRenderTexture* sfRenderTexture_create(sfVector2u size, const sfContextSettings if (!renderTexture->resize(convertVector2(size), params)) return nullptr; - renderTexture->Target = std::make_unique(const_cast(&renderTexture->getTexture())); + renderTexture->Target = sfTexture{renderTexture->getTexture()}; renderTexture->DefaultView = sfView{renderTexture->getDefaultView()}; renderTexture->CurrentView = sfView{renderTexture->getView()}; @@ -300,7 +300,7 @@ void sfRenderTexture_resetGLStates(sfRenderTexture* renderTexture) const sfTexture* sfRenderTexture_getTexture(const sfRenderTexture* renderTexture) { assert(renderTexture); - return renderTexture->Target.get(); + return &renderTexture->Target; } diff --git a/src/CSFML/Graphics/RenderTextureStruct.hpp b/src/CSFML/Graphics/RenderTextureStruct.hpp index 74f40cf..9aba4f8 100644 --- a/src/CSFML/Graphics/RenderTextureStruct.hpp +++ b/src/CSFML/Graphics/RenderTextureStruct.hpp @@ -32,15 +32,13 @@ #include -#include - //////////////////////////////////////////////////////////// // Internal structure of sfRenderTexture //////////////////////////////////////////////////////////// struct sfRenderTexture : sf::RenderTexture { - std::unique_ptr Target; - sfView DefaultView; - sfView CurrentView; + sfTexture Target; + sfView DefaultView; + sfView CurrentView; }; diff --git a/src/CSFML/Graphics/Shader.cpp b/src/CSFML/Graphics/Shader.cpp index bc95236..d20793b 100644 --- a/src/CSFML/Graphics/Shader.cpp +++ b/src/CSFML/Graphics/Shader.cpp @@ -346,7 +346,8 @@ void sfShader_setTextureUniform(sfShader* shader, const char* name, const sfText { assert(shader); assert(name); - shader->setUniform(name, *texture->This); + assert(texture); + shader->setUniform(name, *texture); } @@ -419,7 +420,7 @@ void sfShader_setTextureParameter(sfShader* shader, const char* name, const sfTe assert(shader); assert(name); assert(texture); - shader->setUniform(name, *texture->This); + shader->setUniform(name, *texture); } diff --git a/src/CSFML/Graphics/Shape.cpp b/src/CSFML/Graphics/Shape.cpp index 43745f0..5372ee5 100644 --- a/src/CSFML/Graphics/Shape.cpp +++ b/src/CSFML/Graphics/Shape.cpp @@ -159,7 +159,7 @@ sfTransform sfShape_getInverseTransform(const sfShape* shape) void sfShape_setTexture(sfShape* shape, const sfTexture* texture, bool resetRect) { assert(shape); - shape->setTexture(texture ? texture->This : nullptr, resetRect); + shape->setTexture(texture, resetRect); shape->Texture = texture; } diff --git a/src/CSFML/Graphics/Sprite.cpp b/src/CSFML/Graphics/Sprite.cpp index 34933b5..1ba25d2 100644 --- a/src/CSFML/Graphics/Sprite.cpp +++ b/src/CSFML/Graphics/Sprite.cpp @@ -40,8 +40,7 @@ sfSprite* sfSprite_create(const sfTexture* texture) { assert(texture); - assert(texture->This); - auto sprite = new sfSprite(*texture->This); + auto sprite = new sfSprite(*texture); sprite->Texture = texture; return sprite; } @@ -171,10 +170,10 @@ sfTransform sfSprite_getInverseTransform(const sfSprite* sprite) //////////////////////////////////////////////////////////// void sfSprite_setTexture(sfSprite* sprite, const sfTexture* texture, bool resetRect) { - if (texture && texture->This) + if (texture) { assert(sprite); - sprite->setTexture(*texture->This, resetRect); + sprite->setTexture(*texture, resetRect); sprite->Texture = texture; } } diff --git a/src/CSFML/Graphics/Texture.cpp b/src/CSFML/Graphics/Texture.cpp index 113ca16..789f5c9 100644 --- a/src/CSFML/Graphics/Texture.cpp +++ b/src/CSFML/Graphics/Texture.cpp @@ -41,7 +41,7 @@ sfTexture* sfTexture_create(sfVector2u size) { auto texture = std::make_unique(); - if (!texture->This->resize(convertVector2(size))) + if (!texture->resize(convertVector2(size))) return nullptr; return texture.release(); @@ -52,7 +52,7 @@ sfTexture* sfTexture_create(sfVector2u size) sfTexture* sfTexture_createSrgb(sfVector2u size) { auto texture = std::make_unique(); - if (!texture->This->resize(convertVector2(size), true)) + if (!texture->resize(convertVector2(size), true)) return nullptr; return texture.release(); @@ -65,7 +65,7 @@ sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area) assert(filename); auto texture = std::make_unique(); - if (!texture->This->loadFromFile(filename, false, area ? convertRect(*area) : sf::IntRect())) + if (!texture->loadFromFile(filename, false, area ? convertRect(*area) : sf::IntRect())) return nullptr; return texture.release(); @@ -77,7 +77,7 @@ sfTexture* sfTexture_createSrgbFromFile(const char* filename, const sfIntRect* a assert(filename); auto texture = std::make_unique(); - if (!texture->This->loadFromFile(filename, true, area ? convertRect(*area) : sf::IntRect())) + if (!texture->loadFromFile(filename, true, area ? convertRect(*area) : sf::IntRect())) return nullptr; return texture.release(); @@ -87,7 +87,7 @@ sfTexture* sfTexture_createSrgbFromFile(const char* filename, const sfIntRect* a sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area) { auto texture = std::make_unique(); - if (!texture->This->loadFromMemory(data, sizeInBytes, false, area ? convertRect(*area) : sf::IntRect())) + if (!texture->loadFromMemory(data, sizeInBytes, false, area ? convertRect(*area) : sf::IntRect())) return nullptr; return texture.release(); @@ -97,7 +97,7 @@ sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, cons sfTexture* sfTexture_createSrgbFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area) { auto texture = std::make_unique(); - if (!texture->This->loadFromMemory(data, sizeInBytes, true, area ? convertRect(*area) : sf::IntRect())) + if (!texture->loadFromMemory(data, sizeInBytes, true, area ? convertRect(*area) : sf::IntRect())) return nullptr; return texture.release(); @@ -111,7 +111,7 @@ sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* ar CallbackStream sfmlStream(stream); auto texture = std::make_unique(); - if (!texture->This->loadFromStream(sfmlStream, false, area ? convertRect(*area) : sf::IntRect())) + if (!texture->loadFromStream(sfmlStream, false, area ? convertRect(*area) : sf::IntRect())) return nullptr; return texture.release(); @@ -124,7 +124,7 @@ sfTexture* sfTexture_createSrgbFromStream(sfInputStream* stream, const sfIntRect CallbackStream sfmlStream(stream); auto texture = std::make_unique(); - if (!texture->This->loadFromStream(sfmlStream, true, area ? convertRect(*area) : sf::IntRect())) + if (!texture->loadFromStream(sfmlStream, true, area ? convertRect(*area) : sf::IntRect())) return nullptr; return texture.release(); @@ -137,7 +137,7 @@ sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area assert(image); auto texture = std::make_unique(); - if (!texture->This->loadFromImage(*image, false, area ? convertRect(*area) : sf::IntRect())) + if (!texture->loadFromImage(*image, false, area ? convertRect(*area) : sf::IntRect())) return nullptr; return texture.release(); @@ -149,7 +149,7 @@ sfTexture* sfTexture_createSrgbFromImage(const sfImage* image, const sfIntRect* assert(image); auto texture = std::make_unique(); - if (!texture->This->loadFromImage(*image, true, area ? convertRect(*area) : sf::IntRect())) + if (!texture->loadFromImage(*image, true, area ? convertRect(*area) : sf::IntRect())) return nullptr; return texture.release(); @@ -174,7 +174,7 @@ void sfTexture_destroy(const sfTexture* texture) sfVector2u sfTexture_getSize(const sfTexture* texture) { assert(texture); - return convertVector2(texture->This->getSize()); + return convertVector2(texture->getSize()); } @@ -182,8 +182,7 @@ sfVector2u sfTexture_getSize(const sfTexture* texture) sfImage* sfTexture_copyToImage(const sfTexture* texture) { assert(texture); - assert(texture->This); - return new sfImage{texture->This->copyToImage()}; + return new sfImage{texture->copyToImage()}; } @@ -191,7 +190,7 @@ sfImage* sfTexture_copyToImage(const sfTexture* texture) void sfTexture_updateFromPixels(sfTexture* texture, const uint8_t* pixels, sfVector2u size, sfVector2u offset) { assert(texture); - texture->This->update(pixels, convertVector2(size), convertVector2(offset)); + texture->update(pixels, convertVector2(size), convertVector2(offset)); } @@ -200,8 +199,7 @@ void sfTexture_updateFromTexture(sfTexture* destination, const sfTexture* textur { assert(destination); assert(texture); - assert(texture->This); - destination->This->update(*texture->This, convertVector2(offset)); + destination->update(*texture, convertVector2(offset)); } @@ -210,7 +208,7 @@ void sfTexture_updateFromImage(sfTexture* texture, const sfImage* image, sfVecto { assert(texture); assert(image); - texture->This->update(*image, convertVector2(offset)); + texture->update(*image, convertVector2(offset)); } @@ -219,7 +217,7 @@ void sfTexture_updateFromWindow(sfTexture* texture, const sfWindow* window, sfVe { assert(texture); assert(window); - texture->This->update(*window, convertVector2(offset)); + texture->update(*window, convertVector2(offset)); } @@ -228,7 +226,7 @@ void sfTexture_updateFromRenderWindow(sfTexture* texture, const sfRenderWindow* { assert(texture); assert(renderWindow); - texture->This->update(*renderWindow, convertVector2(offset)); + texture->update(*renderWindow, convertVector2(offset)); } @@ -236,7 +234,7 @@ void sfTexture_updateFromRenderWindow(sfTexture* texture, const sfRenderWindow* void sfTexture_setSmooth(sfTexture* texture, bool smooth) { assert(texture); - texture->This->setSmooth(smooth); + texture->setSmooth(smooth); } @@ -244,15 +242,14 @@ void sfTexture_setSmooth(sfTexture* texture, bool smooth) bool sfTexture_isSmooth(const sfTexture* texture) { assert(texture); - assert(texture->This); - return texture->This->isSmooth(); + return texture->isSmooth(); } //////////////////////////////////////////////////////////// bool sfTexture_isSrgb(const sfTexture* texture) { assert(texture); - return texture->This->isSrgb(); + return texture->isSrgb(); } @@ -260,7 +257,7 @@ bool sfTexture_isSrgb(const sfTexture* texture) void sfTexture_setRepeated(sfTexture* texture, bool repeated) { assert(texture); - texture->This->setRepeated(repeated); + texture->setRepeated(repeated); } @@ -268,8 +265,7 @@ void sfTexture_setRepeated(sfTexture* texture, bool repeated) bool sfTexture_isRepeated(const sfTexture* texture) { assert(texture); - assert(texture->This); - return texture->This->isRepeated(); + return texture->isRepeated(); } @@ -277,7 +273,7 @@ bool sfTexture_isRepeated(const sfTexture* texture) bool sfTexture_generateMipmap(sfTexture* texture) { assert(texture); - return texture->This->generateMipmap(); + return texture->generateMipmap(); } @@ -286,7 +282,7 @@ void sfTexture_swap(sfTexture* left, sfTexture* right) { assert(left); assert(right); - left->This->swap(*right->This); + left->swap(*right); } @@ -294,14 +290,14 @@ void sfTexture_swap(sfTexture* left, sfTexture* right) unsigned int sfTexture_getNativeHandle(const sfTexture* texture) { assert(texture); - return texture->This->getNativeHandle(); + return texture->getNativeHandle(); } //////////////////////////////////////////////////////////// void sfTexture_bind(const sfTexture* texture, sfTextureCoordinateType type) { - sf::Texture::bind(texture ? texture->This : nullptr, static_cast(type)); + sf::Texture::bind(texture, static_cast(type)); } diff --git a/src/CSFML/Graphics/TextureStruct.hpp b/src/CSFML/Graphics/TextureStruct.hpp index 775bd88..90411ef 100644 --- a/src/CSFML/Graphics/TextureStruct.hpp +++ b/src/CSFML/Graphics/TextureStruct.hpp @@ -33,24 +33,6 @@ //////////////////////////////////////////////////////////// // Internal structure of sfTexture //////////////////////////////////////////////////////////// -struct sfTexture +struct sfTexture : sf::Texture { - sfTexture() = default; - - sfTexture(sf::Texture* texture) : This(texture), OwnInstance(false) - { - } - - sfTexture(const sfTexture& texture) : This(texture.This ? new sf::Texture(*texture.This) : nullptr) - { - } - - ~sfTexture() - { - if (OwnInstance) - delete This; - } - - sf::Texture* This{new sf::Texture}; - bool OwnInstance{true}; };