From: Côme Chilliet Date: Sat, 26 Nov 2016 08:47:44 +0000 (+0800) Subject: Got rid of global texture var. Calling load_image directly X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=a7c9ba64aa7413abb4c566dad8dc796526952d3e;p=lugaru.git Got rid of global texture var. Calling load_image directly --- diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index 0ce61ee..79a6a8d 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -52,7 +52,6 @@ extern float multiplier; extern int netdatanew; extern float mapinfo; extern bool stillloading; -extern ImageRec texture; extern short vRefNum; extern long dirID; extern int mainmenu; @@ -120,10 +119,6 @@ void Dispose() } OPENAL_Close(); - if (texture.data) { - free(texture.data); - } - texture.data = 0; #endif } @@ -170,7 +165,8 @@ void LoadSave(const char *fileName, GLuint *textureid, bool mipmap, GLubyte *arr texdetail = 1; //Load Image - upload_image(ConvertFileName(fileName)); + ImageRec texture; + load_image(ConvertFileName(fileName), texture); texdetail = temptexdetail; int bytesPerPixel = texture.bpp / 8; @@ -569,8 +565,6 @@ void Game::InitGame() stillloading = 1; - texture.data = ( GLubyte* )malloc( 1024 * 1024 * 4 ); - int temptexdetail = texdetail; texdetail = 1; text->LoadFontTexture(":Data:Textures:Font.png"); diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index c767097..ea59163 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -125,7 +125,6 @@ extern float damagedealt; extern int maptype; extern int editoractive; extern int editorpathtype; -extern ImageRec texture; extern float hostiletime; @@ -388,7 +387,8 @@ bool Game::AddClothes(const char *fileName, GLubyte *array) { LOGFUNC; //Load Image - bool opened = upload_image(fileName); + ImageRec texture; + bool opened = load_image(fileName, texture); float alphanum; //Is it valid? diff --git a/Source/Globals.cpp b/Source/Globals.cpp index 2969af5..2d3da97 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -178,7 +178,6 @@ bool tiltweird = false; bool midweird = false; bool proportionweird = false; bool vertexweird[6] = {0}; -ImageRec texture; bool debugmode = false; diff --git a/Source/ImageIO.cpp b/Source/ImageIO.cpp index eaeef5f..affcb8c 100644 --- a/Source/ImageIO.cpp +++ b/Source/ImageIO.cpp @@ -28,7 +28,6 @@ along with Lugaru. If not, see . #include "Game.h" #include "ImageIO.h" -extern ImageRec texture; extern bool visibleloading; /* These two are needed for screenshot */ @@ -39,9 +38,15 @@ static bool load_png(const char * fname, ImageRec & tex); static bool load_jpg(const char * fname, ImageRec & tex); static bool save_screenshot_png(const char * fname); -bool upload_image(const char* fileName) +ImageRec::ImageRec() { - return load_image(fileName, texture); + data = ( GLubyte* )malloc( 1024 * 1024 * 4 ); +} + +ImageRec::~ImageRec() +{ + free(data); + data = NULL; } bool load_image(const char *file_name, ImageRec &tex) diff --git a/Source/ImageIO.h b/Source/ImageIO.h index 7fc2ff9..b3d0a49 100644 --- a/Source/ImageIO.h +++ b/Source/ImageIO.h @@ -41,14 +41,20 @@ along with Lugaru. If not, see . #endif /**> DATA STRUCTURES <**/ -typedef struct ImageRec { +class ImageRec { +public: GLubyte *data; // Image Data (Up To 32 Bits) GLuint bpp; // Image Color Depth In Bits Per Pixel. GLuint sizeX; GLuint sizeY; -} ImageRec; + ImageRec(); + ~ImageRec(); +private: + /* Make sure this class cannot be copied to avoid memory problems */ + ImageRec(ImageRec const &); + ImageRec& operator=(ImageRec const &); +}; -bool upload_image(const char* filePath); bool load_image(const char * fname, ImageRec & tex); bool save_screenshot(const char * fname); diff --git a/Source/Terrain.cpp b/Source/Terrain.cpp index af56b86..9061f37 100644 --- a/Source/Terrain.cpp +++ b/Source/Terrain.cpp @@ -35,7 +35,6 @@ extern bool decals; extern float blurness; extern float targetblurness; extern Objects objects; -extern ImageRec texture; extern bool visibleloading; extern bool skyboxtexture; extern int tutoriallevel; @@ -405,8 +404,10 @@ bool Terrain::load(const char *fileName) float temptexdetail = texdetail; + ImageRec texture; + //Load Image - upload_image(ConvertFileName(fileName)); + load_image(ConvertFileName(fileName), texture); //Is it valid? if (texture.bpp > 24) { diff --git a/Source/Texture.cpp b/Source/Texture.cpp index adbef9f..08010c3 100644 --- a/Source/Texture.cpp +++ b/Source/Texture.cpp @@ -24,15 +24,16 @@ along with Lugaru. If not, see . using namespace std; -extern ImageRec texture; extern bool trilinear; vector TextureRes::list; void TextureRes::load() { - //load image into 'texture' global var - upload_image(ConvertFileName(filename.c_str())); + ImageRec texture; + + //load image into 'texture' + load_image(ConvertFileName(filename.c_str()), texture); skinsize = texture.sizeX; GLuint type = GL_RGBA;