]> git.jsancho.org Git - lugaru.git/commitdiff
Cleaned up TextureRes lifecycle to make sure it’s destroyed by RAII
authorCôme Chilliet <come@chilliet.eu>
Thu, 15 Dec 2016 13:51:01 +0000 (20:51 +0700)
committerCôme Chilliet <come@chilliet.eu>
Thu, 15 Dec 2016 13:51:01 +0000 (20:51 +0700)
13 files changed:
Source/Environment/Skybox.cpp
Source/Environment/Skybox.hpp
Source/Environment/Terrain.cpp
Source/Environment/Terrain.hpp
Source/GameInitDispose.cpp
Source/Graphic/Models.cpp
Source/Graphic/Sprite.cpp
Source/Graphic/Sprite.hpp
Source/Graphic/Text.cpp
Source/Graphic/Texture.cpp
Source/Graphic/Texture.hpp
Source/Objects/Weapons.cpp
Source/Objects/Weapons.hpp

index 97dcd6da08d3ea64ac7c115b81a1acce18ac495c..5ace90a08fac8d03210b9027324e878c3fb75eae 100644 (file)
@@ -158,13 +158,3 @@ void SkyBox::draw()
     glDepthMask(1);
     glPopMatrix();
 }
-
-SkyBox::~SkyBox()
-{
-    front.destroy();
-    left.destroy();
-    back.destroy();
-    right.destroy();
-    up.destroy();
-    down.destroy();
-}
index 1a9d36a2fec5c66cfeffde420368bfda13167f8a..2fb2d5daaa844e5669acc3b7f8baee4b56a83b53 100644 (file)
@@ -37,7 +37,6 @@ public:
     void draw();
 
     SkyBox() {}
-    ~SkyBox();
 };
 
 #endif
index 77ae539fb4af977cfc335c76630e63dea60df39e..806bb4be7541b30f4f5b0cda08011ac5451db80d 100644 (file)
@@ -1515,14 +1515,3 @@ Terrain::Terrain()
     memset(decalposition, 0, sizeof(decalposition));
     numdecals = 0;
 }
-Terrain::~Terrain()
-{
-    terraintexture.destroy();
-    shadowtexture.destroy();
-    bodyprinttexture.destroy();
-    footprinttexture.destroy();
-    bloodtexture.destroy();
-    bloodtexture2.destroy();
-    breaktexture.destroy();
-}
-
index 3c30e3d6724f461d1144ed1fa2c5cbd36fb0e893..097cdbd375f2bfa28a13edf44be6abfb6672dd96 100644 (file)
@@ -126,7 +126,6 @@ public:
     void DoShadows();
 
     Terrain();
-    ~Terrain();
 };
 
 #endif
index 38815d9ee56206ef427bde0020460026dcae30da..5e6ce040c9d95e197e7cd79186f10398e8b18105 100644 (file)
@@ -114,17 +114,6 @@ void Game::deleteGame()
         delete skybox;
     if (text)
         delete text;
-    terraintexture.destroy();
-    terraintexture2.destroy();
-    cursortexture.destroy();
-    Maparrowtexture.destroy();
-    Mapboxtexture.destroy();
-    Mapcircletexture.destroy();
-    hawktexture.destroy();
-    loadscreentexture.destroy();
-
-    for (int i = 0; i < 10; i++)
-        Mainmenuitems[i].destroy();
 
     glDeleteTextures(1, &screentexture);
     glDeleteTextures(1, &screentexture2);
@@ -663,10 +652,6 @@ void Game::LoadStuff()
 
     stillloading = 1;
 
-    for (auto p:Person::players) {
-        p->skeleton.drawmodel.textureptr.destroy();
-    }
-
     visibleloading = 0; //don't use loadscreentexture yet
     loadscreentexture.load("Textures/Fire.jpg", 1);
     visibleloading = 1;
index 38e2447085c528abba18ce2dfe35c2d77332f4bc..1e5947277b70d4fb2ed0a0ca3794d0191bafbd1e 100644 (file)
@@ -1358,7 +1358,6 @@ void Model::MakeDecal(int atype, XYZ where, float size, float opacity, float rot
 Model::~Model()
 {
     deallocate();
-    textureptr.destroy();
 }
 
 void Model::deallocate()
index 3f582f95f9b2e724b72a96b8d5eeea75293c7d62..0fb5a40fcf33ea721d6bfced47d59a01f630f046 100644 (file)
@@ -462,19 +462,3 @@ Sprite::Sprite()
     speed = 0;
     rotatespeed = 0;
 }
-
-void Sprite::clearTextures()
-{
-    toothtexture.destroy();
-    cloudtexture.destroy();
-    cloudimpacttexture.destroy();
-    bloodtexture.destroy();
-    flametexture.destroy();
-    bloodflametexture.destroy();
-    smoketexture.destroy();
-    snowflaketexture.destroy();
-    shinetexture.destroy();
-    splintertexture.destroy();
-    leaftexture.destroy();
-}
-
index 66debe7dfbfc0a9f3c44aebf10b644390aa135db..0eb1d19b261cd0869d743e630933b1dedde8d626 100644 (file)
@@ -86,7 +86,6 @@ public:
     static void setLastSpriteAlivetime(float al) {
         sprites.back()->alivetime = al;
     }
-    static void clearTextures();
 
     static Texture cloudtexture;
     static Texture bloodtexture;
index 2cf73aa60208d169ccc1a8710f652bc38ecb7943..1253ba9d474f73eb56ac487f80310b024bf05aa8 100644 (file)
@@ -147,6 +147,5 @@ Text::~Text()
         glDeleteLists(base, 512);
         base = 0;
     }
-    FontTexture.destroy();
 }
 
index fe732bfd3314e9802afb354776fa57b0a948aba7..9dd4ea60be08eac20d5fbc66e04125598944c0b9 100644 (file)
@@ -89,8 +89,9 @@ TextureRes::TextureRes(const string& _filename, bool _hasMipmap, GLubyte* array,
 {
     load();
     *skinsizep = skinsize;
-    for (int i = 0; i < datalen; i++)
+    for (int i = 0; i < datalen; i++) {
         array[i] = data[i];
+    }
 }
 
 TextureRes::~TextureRes()
@@ -101,22 +102,12 @@ TextureRes::~TextureRes()
 
 void Texture::load(const string& filename, bool hasMipmap)
 {
-    destroy();
-    tex = new TextureRes(Folders::getResourcePath(filename), hasMipmap);
+    tex.reset(new TextureRes(Folders::getResourcePath(filename), hasMipmap));
 }
 
 void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep)
 {
-    destroy();
-    tex = new TextureRes(Folders::getResourcePath(filename), hasMipmap, array, skinsizep);
-}
-
-void Texture::destroy()
-{
-    if (tex) {
-        delete tex;
-        tex = NULL;
-    }
+    tex.reset(new TextureRes(Folders::getResourcePath(filename), hasMipmap, array, skinsizep));
 }
 
 void Texture::bind()
index 0f1282898053bd6b56310860f7db2fd046dd5d5d..54df61336cdecc4d6ba849d5fab29f9ba2a0a697 100644 (file)
@@ -26,8 +26,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include <map>
 #include <string>
 #include <vector>
-
-using namespace std;
+#include <memory>
 
 class TextureRes
 {
@@ -47,17 +46,20 @@ public:
     TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize);
     ~TextureRes();
     void bind();
+
+    /* Make sure TextureRes never gets copied */
+    TextureRes(TextureRes const& other) = delete;
+    TextureRes & operator=(TextureRes const& other) = delete;
 };
 
 class Texture
 {
 private:
-    TextureRes* tex;
+    std::shared_ptr<TextureRes> tex;
 public:
-    inline Texture(): tex(NULL) {}
+    inline Texture(): tex(nullptr) {}
     void load(const string& filename, bool hasMipmap);
     void load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep);
-    void destroy();
     void bind();
 };
 
index 127c014cb41702bd2c10df4790514184369711e9..d762ddcfa0ad17f973171459a46b0dc7c667853f 100644 (file)
@@ -1111,15 +1111,3 @@ int Weapons::Draw()
 Weapons::Weapons()
 {
 }
-
-Weapons::~Weapons()
-{
-    Weapon::stafftextureptr.destroy();
-    Weapon::knifetextureptr.destroy();
-    Weapon::lightbloodknifetextureptr.destroy();
-    Weapon::bloodknifetextureptr.destroy();
-    Weapon::swordtextureptr.destroy();
-    Weapon::lightbloodswordtextureptr.destroy();
-    Weapon::bloodswordtextureptr.destroy();
-}
-
index 9258e9ef93499e1528031bbafffbd4766e567f49..2897cfb9aa0ffcf4119da603dbe3cb0f30e49b39 100644 (file)
@@ -122,7 +122,6 @@ class Weapons : public std::vector<Weapon>
 {
 public:
     Weapons();
-    ~Weapons();
 
     int Draw();
     void DoStuff();