From: Côme Chilliet Date: Thu, 24 Nov 2016 09:27:32 +0000 (+0800) Subject: First step at cleaning image loading. X-Git-Url: https://git.jsancho.org/?p=lugaru.git;a=commitdiff_plain;h=34ce0cdd42f673a04aa29ae148d2206420dfd813 First step at cleaning image loading. Removed all weird pascal string stuff Next step is to remove this texture global var, use load_image directly and delete TGALoader.* --- diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index c766332..60727a7 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -53,7 +53,7 @@ extern float multiplier; extern int netdatanew; extern float mapinfo; extern bool stillloading; -extern TGAImageRec texture; +extern ImageRec texture; extern short vRefNum; extern long dirID; extern int mainmenu; @@ -170,14 +170,8 @@ void LoadSave(const char *fileName, GLuint *textureid, bool mipmap, GLubyte *arr float temptexdetail = texdetail; texdetail = 1; - // Converting file to something os specific - char * fixedFN = ConvertFileName(fileName); - - //Load Image - unsigned char fileNamep[256]; - CopyCStringToPascal(fixedFN, fileNamep); //Load Image - upload_image( fileNamep , 0); + upload_image(ConvertFileName(fileName)); texdetail = temptexdetail; int bytesPerPixel = texture.bpp / 8; diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index e1851c6..2136af6 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -124,7 +124,7 @@ extern float damagedealt; extern int maptype; extern int editoractive; extern int editorpathtype; -extern TGAImageRec texture; +extern ImageRec texture; extern float hostiletime; @@ -387,10 +387,7 @@ bool Game::AddClothes(const char *fileName, GLubyte *array) { LOGFUNC; //Load Image - unsigned char fileNamep[256]; - CopyCStringToPascal(fileName, fileNamep); - bool opened; - opened = upload_image(fileNamep, 1); + bool opened = upload_image(fileName); float alphanum; //Is it valid? diff --git a/Source/Globals.cpp b/Source/Globals.cpp index 47be452..5fc6c55 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -178,7 +178,7 @@ bool tiltweird = false; bool midweird = false; bool proportionweird = false; bool vertexweird[6] = {0}; -TGAImageRec texture; +ImageRec texture; bool debugmode = false; diff --git a/Source/MacCompatibility.cpp b/Source/MacCompatibility.cpp index 7e06997..b536234 100644 --- a/Source/MacCompatibility.cpp +++ b/Source/MacCompatibility.cpp @@ -69,23 +69,6 @@ public: }; static AppTime g_appTime; - -void CopyCStringToPascal( const char* src, unsigned char dst[256]) -{ - int len = strlen( src); - dst[ 0] = len; - memcpy( dst + 1, src, len); -} - - -void CopyPascalStringToC( const unsigned char* src, char* dst) -{ - int len = src[ 0]; - memcpy( dst, src + 1, len); - dst[ len] = 0; -} - - AbsoluteTime UpTime() { __int64 counter; diff --git a/Source/MacCompatibility.h b/Source/MacCompatibility.h index 1bade1c..7786a95 100644 --- a/Source/MacCompatibility.h +++ b/Source/MacCompatibility.h @@ -62,11 +62,6 @@ typedef unsigned int UInt32; #include "Random.h" - -void CopyCStringToPascal( const char* src, unsigned char dst[256]); -void CopyPascalStringToC( const unsigned char* src, char* dst); - - typedef struct AbsoluteTime { unsigned long hi; unsigned long lo; diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index 4f4abc6..45e7b8b 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -30,9 +30,9 @@ along with Lugaru. If not, see . using namespace Game; -static bool load_image(const char * fname, TGAImageRec & tex); -static bool load_png(const char * fname, TGAImageRec & tex); -static bool load_jpg(const char * fname, TGAImageRec & tex); +bool load_image(const char * fname, ImageRec & tex); +static bool load_png(const char * fname, ImageRec & tex); +static bool load_jpg(const char * fname, ImageRec & tex); bool save_image(const char * fname); static bool save_png(const char * fname); @@ -55,6 +55,7 @@ bool gameFocused; extern float slomospeed; extern float slomofreq; +extern bool visibleloading; @@ -760,17 +761,14 @@ int main(int argc, char **argv) // -------------------------------------------------------------------------- - -bool LoadImage(const char * fname, TGAImageRec & tex) +bool load_image(const char *file_name, ImageRec &tex) { + if (visibleloading) + Game::LoadingScreen(); + if ( tex.data == NULL ) return false; - else - return load_image(fname, tex); -} -static bool load_image(const char *file_name, TGAImageRec &tex) -{ const char *ptr = strrchr((char *)file_name, '.'); if (ptr) { if (strcasecmp(ptr + 1, "png") == 0) @@ -783,7 +781,6 @@ static bool load_image(const char *file_name, TGAImageRec &tex) return false; } - struct my_error_mgr { struct jpeg_error_mgr pub; /* "public" fields */ jmp_buf setjmp_buffer; /* for return to caller */ @@ -798,7 +795,7 @@ static void my_error_exit(j_common_ptr cinfo) } /* stolen from public domain example.c code in libjpg distribution. */ -static bool load_jpg(const char *file_name, TGAImageRec &tex) +static bool load_jpg(const char *file_name, ImageRec &tex) { struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; @@ -846,7 +843,7 @@ static bool load_jpg(const char *file_name, TGAImageRec &tex) /* stolen from public domain example.c code in libpng distribution. */ -static bool load_png(const char *file_name, TGAImageRec &tex) +static bool load_png(const char *file_name, ImageRec &tex) { bool hasalpha = false; png_structp png_ptr = NULL; diff --git a/Source/TGALoader.cpp b/Source/TGALoader.cpp index c9796b5..45bde23 100644 --- a/Source/TGALoader.cpp +++ b/Source/TGALoader.cpp @@ -21,21 +21,11 @@ along with Lugaru. If not, see . #include "Game.h" #include "TGALoader.h" -extern float texdetail; -extern TGAImageRec texture; -extern short vRefNum; -extern long dirID; -extern bool visibleloading; - -extern bool LoadImage(const char * fname, TGAImageRec & tex); -/********************> LoadTGA() <*****/ -bool upload_image(const unsigned char* filePath, bool hasalpha) -{ - if (visibleloading) - Game::LoadingScreen(); +extern ImageRec texture; + +extern bool load_image(const char * fname, ImageRec & tex); - // for Windows, just use TGA loader for now - char fileName[256]; - CopyPascalStringToC( filePath, fileName); - return (LoadImage(fileName, texture)); +bool upload_image(const char* fileName) +{ + return load_image(fileName, texture); } diff --git a/Source/TGALoader.h b/Source/TGALoader.h index 0210e13..d8f3336 100644 --- a/Source/TGALoader.h +++ b/Source/TGALoader.h @@ -37,21 +37,17 @@ along with Lugaru. If not, see . #include "GL/gl.h" #else #include "gamegl.h" -// #include "MoreFilesX.h" #endif -//#include -//#include - /**> DATA STRUCTURES <**/ -typedef struct TGAImageRec { +typedef struct ImageRec { GLubyte *data; // Image Data (Up To 32 Bits) GLuint bpp; // Image Color Depth In Bits Per Pixel. GLuint sizeX; GLuint sizeY; -} TGAImageRec; +} ImageRec; -bool upload_image(const unsigned char* filePath, bool hasalpha); +bool upload_image(const char* filePath); #endif diff --git a/Source/Terrain.cpp b/Source/Terrain.cpp index 38bf0ae..08a9f71 100644 --- a/Source/Terrain.cpp +++ b/Source/Terrain.cpp @@ -34,7 +34,7 @@ extern bool decals; extern float blurness; extern float targetblurness; extern Objects objects; -extern TGAImageRec texture; +extern ImageRec texture; extern bool visibleloading; extern bool skyboxtexture; extern int tutoriallevel; @@ -404,15 +404,9 @@ bool Terrain::load(const char *fileName) static float patch_size; float temptexdetail = texdetail; - //LoadTGA( fileName ); - // Fixing filename so that it works with its own os - char * FixedFN = ConvertFileName(fileName); - - unsigned char fileNamep[256]; - CopyCStringToPascal(FixedFN, fileNamep); //Load Image - upload_image( fileNamep , 0); + upload_image(ConvertFileName(fileName)); //Is it valid? if (texture.bpp > 24) { diff --git a/Source/Text.cpp b/Source/Text.cpp index 8d0dc60..d316048 100644 --- a/Source/Text.cpp +++ b/Source/Text.cpp @@ -20,7 +20,6 @@ along with Lugaru. If not, see . /**> HEADER FILES <**/ #include "Text.h" #include "Game.h" -extern TGAImageRec texture; void Text::LoadFontTexture(const char *fileName) { diff --git a/Source/Texture.cpp b/Source/Texture.cpp index a9c69cf..2d3f2a8 100644 --- a/Source/Texture.cpp +++ b/Source/Texture.cpp @@ -23,7 +23,7 @@ along with Lugaru. If not, see . using namespace std; -extern TGAImageRec texture; +extern ImageRec texture; extern bool trilinear; @@ -60,9 +60,7 @@ void TextureRes::load() { //load image into 'texture' global var if (!skindata) { - unsigned char filenamep[256]; - CopyCStringToPascal(ConvertFileName(filename.c_str()), filenamep); - upload_image(filenamep, hasAlpha); + upload_image(ConvertFileName(filename.c_str())); } skinsize = texture.sizeX; @@ -148,8 +146,6 @@ void TextureRes::reloadAll() } - - void Texture::load(const string& filename, bool hasMipmap, bool hasAlpha) { destroy(); diff --git a/Source/WinDefs.cpp b/Source/WinDefs.cpp index 36bf595..fd49c10 100644 --- a/Source/WinDefs.cpp +++ b/Source/WinDefs.cpp @@ -39,24 +39,6 @@ public: }; static AppTime g_appTime; - - -void CopyCStringToPascal( const char* src, unsigned char dst[256]) -{ - int len = strlen( src); - dst[0] = len; - memcpy( dst + 1, src, len); -} - - -void CopyPascalStringToC( const unsigned char* src, char* dst) -{ - int len = src[0]; - memcpy( dst, src + 1, len); - dst[len] = 0; -} - - AbsoluteTime UpTime() { __int64 counter; diff --git a/Source/WinDefs.h b/Source/WinDefs.h index cbee4ea..3ac74d5 100644 --- a/Source/WinDefs.h +++ b/Source/WinDefs.h @@ -52,10 +52,6 @@ typedef unsigned int UInt32; #include "Random.h" -void CopyCStringToPascal( const char* src, unsigned char dst[256]); -void CopyPascalStringToC( const unsigned char* src, char* dst); - - typedef struct AbsoluteTime { unsigned long hi; unsigned long lo;