X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGameInitDispose.cpp;h=eb55bb39fb04c548dda355eba633d036fd4bf40c;hb=72621d52ae69fa4ecb4329437810d71860ae3ebc;hp=e4f2e394035b428aa6e0714e6a75069e580120db;hpb=8dda34d525dcb410195a05592fa72cef1954777b;p=lugaru.git diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index e4f2e39..eb55bb3 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Game.h" #include "openal_wrapper.h" #include "Animation.h" +#include "Texture.h" extern float screenwidth,screenheight; extern float viewdistance; @@ -39,7 +40,6 @@ extern Terrain terrain; extern int kTextureSize; extern float texdetail; extern float realtexdetail; -extern float terraindetail; extern float volume; extern Objects objects; extern int detail; @@ -62,7 +62,6 @@ extern long dirID; extern int mainmenu; extern int oldmainmenu; extern bool visibleloading; -extern int loadscreencolor; extern float flashamount,flashr,flashg,flashb; extern int flashdelay; extern int whichjointstartarray[26]; @@ -100,13 +99,8 @@ void LOG(const std::string &fmt, ...) // !!! FIXME: write me. } - -Game::TextureList Game::textures; - void Game::Dispose() { - int i,j; - LOGFUNC; if(endgame==2){ @@ -116,13 +110,7 @@ void Game::Dispose() Account::saveFile(":Data:Users", accountactive); - TexIter it = textures.begin(); - for (; it != textures.end(); ++it) - { - if (glIsTexture(it->second)) - glDeleteTextures(1, &it->second); - } - textures.clear(); + //textures.clear(); LOG("Shutting down sound system..."); @@ -132,7 +120,7 @@ void Game::Dispose() // later in the shutdown process. --ryan. #if !PLATFORM_LINUX - for (i=0; i < sounds_count; ++i) + for (int i=0; i < sounds_count; ++i) { OPENAL_Sample_Free(samp[i]); } @@ -147,114 +135,12 @@ void Game::Dispose() } -void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha) -{ - GLuint type; - - LOGFUNC; - - LOG(std::string("Loading texture...") + fileName); - - // Fix filename so that is os appropreate - char * fixedFN = ConvertFileName(fileName); - - unsigned char fileNamep[256]; - CopyCStringToPascal(fixedFN, fileNamep); - //Load Image - upload_image( fileNamep ,hasalpha); - -// std::string fname(fileName); -// std::transform(fname.begin(), fname.end(), tolower); -// TexIter it = textures.find(fname); - - //Is it valid? - if(1==1) - //if(textures.end() == it) - { - //Alpha channel? - if ( texture.bpp == 24 ) - type = GL_RGB; - else - type = GL_RGBA; - - glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); - - if(!*textureid) - glGenTextures( 1, textureid ); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - - glBindTexture( GL_TEXTURE_2D, *textureid); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); - if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); - if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - - gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data ); - } +void Game::LoadTexture(const string fileName, GLuint *textureid,int mipmap, bool hasalpha) { + *textureid = Texture::Load(fileName,mipmap,hasalpha); } -void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize) -{ - GLuint type; - int i; - int bytesPerPixel; - - LOGFUNC; - - LOG(std::string("Loading texture (S)...") + fileName); - - //Load Image - unsigned char fileNamep[256]; - CopyCStringToPascal(ConvertFileName(fileName), fileNamep); - //Load Image - upload_image( fileNamep ,0); - //LoadTGA( fileName ); - -// std::string fname(fileName); -// std::transform(fname.begin(), fname.end(), tolower); -// TexIter it = textures.find(fname); - - //Is it valid? - if(1==1) - //if(textures.end() == it) - { - bytesPerPixel=texture.bpp/8; - - //Alpha channel? - if ( texture.bpp == 24 ) - type = GL_RGB; - else - type = GL_RGBA; - - glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); - - if(!*textureid)glGenTextures( 1, textureid ); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - - glBindTexture( GL_TEXTURE_2D, *textureid); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); - if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); - if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - - int tempnum=0; - for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){ - if((i+1)%4||type==GL_RGB){ - array[tempnum]=texture.data[i]; - tempnum++; - } - } - - *skinsize=texture.sizeX; - - gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array ); - -// textures.insert(std::make_pair(fname, *textureid)); - } -// else -// { -// *textureid = it->second; -// } +void Game::LoadTextureSave(const string fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize) { + *textureid = Texture::Load(fileName,mipmap,false,array,skinsize); } void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize) @@ -296,7 +182,7 @@ void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte } } -bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize) +bool Game::AddClothes(const char *fileName, GLubyte *array) { int i; int bytesPerPixel; @@ -366,7 +252,7 @@ GLvoid Game::ReSizeGLScene(float fov, float pnear) void Game::LoadingScreen() { - static float loadprogress,minprogress,maxprogress; + static float loadprogress; static AbsoluteTime time = {0,0}; static AbsoluteTime frametime = {0,0}; AbsoluteTime currTime = UpTime (); @@ -383,7 +269,6 @@ void Game::LoadingScreen() if(multiplier>.05){ frametime = currTime; // reset for next time interval - float size=1; glLoadIdentity(); //Clear to black glClearColor(0,0,0,1); @@ -419,14 +304,6 @@ void Game::LoadingScreen() glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1); - //glColor4f(1,1,1,1); - /*if(loadscreencolor==0)glColor4f(1,1,1,1); - if(loadscreencolor==1)glColor4f(1,0,0,1); - if(loadscreencolor==2)glColor4f(0,1,0,1); - if(loadscreencolor==3)glColor4f(0,0,1,1); - if(loadscreencolor==4)glColor4f(1,1,0,1); - if(loadscreencolor==5)glColor4f(1,0,1,1); - */ glPushMatrix(); //glScalef(.25,.25,.25); glBegin(GL_QUADS); @@ -483,13 +360,6 @@ void Game::LoadingScreen() glEnable(GL_BLEND); //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1); glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1); - /*if(loadscreencolor==0)glColor4f(1,1,1,1); - if(loadscreencolor==1)glColor4f(1,0,0,1); - if(loadscreencolor==2)glColor4f(0,1,0,1); - if(loadscreencolor==3)glColor4f(0,0,1,1); - if(loadscreencolor==4)glColor4f(1,1,0,1); - if(loadscreencolor==5)glColor4f(1,0,1,1); - */ glPushMatrix(); //glScalef(.25,.25,.25); glBegin(GL_QUADS); @@ -553,15 +423,6 @@ void Game::LoadingScreen() glDepthMask(1); //Text - /* - glEnable(GL_TEXTURE_2D); - static char string[256]=""; - sprintf (string, "LOADING... %d%",(int)loadprogress); - glColor4f(1,1,1,.2); - text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480); - glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1); - text.glPrint(280,125,string,1,1,640,480); - */ if(flashamount>0){ if(flashamount>1)flashamount=1; @@ -601,15 +462,13 @@ void Game::LoadingScreen() } swap_gl_buffers(); - loadscreencolor=0; } } void Game::FadeLoadingScreen(float howmuch) { - static float loadprogress,minprogress,maxprogress; + static float loadprogress; - float size=1; glLoadIdentity(); //Clear to black glClearColor(0,0,0,1); @@ -642,13 +501,6 @@ void Game::FadeLoadingScreen(float howmuch) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); glColor4f(loadprogress/100,0,0,1); - /*if(loadscreencolor==0)glColor4f(1,1,1,1); - if(loadscreencolor==1)glColor4f(1,0,0,1); - if(loadscreencolor==2)glColor4f(0,1,0,1); - if(loadscreencolor==3)glColor4f(0,0,1,1); - if(loadscreencolor==4)glColor4f(1,1,0,1); - if(loadscreencolor==5)glColor4f(1,0,1,1); - */ glPushMatrix(); //glScalef(.25,.25,.25); glBegin(GL_QUADS); @@ -670,17 +522,7 @@ void Game::FadeLoadingScreen(float howmuch) glDisable(GL_BLEND); glDepthMask(1); //Text - /* - glEnable(GL_TEXTURE_2D); - static char string[256]=""; - sprintf (string, "LOADING... %d%",(int)loadprogress); - glColor4f(1,1,1,.2); - text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480); - glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1); - text.glPrint(280,125,string,1,1,640,480); - */ swap_gl_buffers(); - loadscreencolor=0; } @@ -710,8 +552,6 @@ void Game::InitGame() autocam=0; - int i,j; - numchallengelevels=14; accountactive=Account::loadFile(":Data:Users"); @@ -814,23 +654,19 @@ void Game::InitGame() if(detail==2){ texdetail=1; - terraindetail=1; } if(detail==1){ texdetail=2; - terraindetail=1; } if(detail==0){ texdetail=4; - terraindetail=1; - //terraindetail=2; } LOG("Initializing sound system..."); - int output = -1; - #if PLATFORM_LINUX + int output = -1; + extern bool cmdline(const char *cmd); unsigned char rc = 0; output = OPENAL_OUTPUT_ALSA; // Try alsa first... @@ -867,7 +703,7 @@ void Game::InitGame() loadAllSounds(); if(musictoggle) - emit_stream_np(stream_music3); + emit_stream_np(stream_menutheme); LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1); @@ -881,14 +717,14 @@ void Game::InitGame() LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0); LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0); LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0); - LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0); LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1); + LoadTexture(":Data:Textures:Resume.png",&Mainmenuitems[5],0,0); + LoadTexture(":Data:Textures:Endgame.png",&Mainmenuitems[6],0,0); + //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1); + //~ LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0); // LoadCampaign will take care of that texdetail=temptexdetail; - loaddistrib=0; - anim=0; - FadeLoadingScreen(95); @@ -905,11 +741,27 @@ void Game::InitGame() } +void Game::LoadScreenTexture() { + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + if(!screentexture) + glGenTextures( 1, &screentexture ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + + glEnable(GL_TEXTURE_2D); + glBindTexture( GL_TEXTURE_2D, screentexture); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0); +} + void Game::LoadStuff() { static float temptexdetail; static float viewdistdetail; - static int i,j,texsize; + static int i,j; float megascale =1; LOGFUNC; @@ -920,8 +772,6 @@ void Game::LoadStuff() stillloading=1; - //texture.data = ( GLubyte* )malloc( 1024*1024*4 ); - for(i=0;i4)texdetail=4; + LoadTexture(":Data:Textures:knife.png",&Weapon::knifetextureptr,0,1); + LoadTexture(":Data:Textures:bloodknife.png",&Weapon::bloodknifetextureptr,0,1); + LoadTexture(":Data:Textures:lightbloodknife.png",&Weapon::lightbloodknifetextureptr,0,1); + LoadTexture(":Data:Textures:sword.jpg",&Weapon::swordtextureptr,1,0); + LoadTexture(":Data:Textures:Swordblood.jpg",&Weapon::bloodswordtextureptr,1,0); + LoadTexture(":Data:Textures:Swordbloodlight.jpg",&Weapon::lightbloodswordtextureptr,1,0); + LoadTexture(":Data:Textures:Staff.jpg",&Weapon::stafftextureptr,1,0); + + Weapon::throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1); + Weapon::throwingknifemodel.Scale(.001,.001,.001); + //Weapon::throwingknifemodel.Rotate(0,0,-90); + Weapon::throwingknifemodel.Rotate(90,0,0); + Weapon::throwingknifemodel.Rotate(0,90,0); + Weapon::throwingknifemodel.flat=0; + Weapon::throwingknifemodel.CalculateNormals(1); + //Weapon::throwingknifemodel.ScaleNormals(-1,-1,-1); + + Weapon::swordmodel.load((char *)":Data:Models:sword.solid",1); + Weapon::swordmodel.Scale(.001,.001,.001); + //Weapon::swordmodel.Rotate(0,0,-90); + Weapon::swordmodel.Rotate(90,0,0); + Weapon::swordmodel.Rotate(0,90,0); + Weapon::swordmodel.Rotate(0,0,90); + Weapon::swordmodel.flat=1; + Weapon::swordmodel.CalculateNormals(1); + //Weapon::swordmodel.ScaleNormals(-1,-1,-1); + + Weapon::staffmodel.load((char *)":Data:Models:staff.solid",1); + Weapon::staffmodel.Scale(.005,.005,.005); + //Weapon::staffmodel.Rotate(0,0,-90); + Weapon::staffmodel.Rotate(90,0,0); + Weapon::staffmodel.Rotate(0,90,0); + Weapon::staffmodel.Rotate(0,0,90); + Weapon::staffmodel.flat=1; + Weapon::staffmodel.CalculateNormals(1); + //Weapon::staffmodel.ScaleNormals(-1,-1,-1); + LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1); LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1); @@ -1038,30 +864,11 @@ void Game::LoadStuff() LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1); - /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1); - - LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1); - - LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1); - - LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1); - - LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1); - - LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1); - //texdetail=temptexdetail; - LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/ - - - LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1); LoadTexture(":Data:Textures:logo.png",&logotexture,0,1); - //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0); - - LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1); LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1); LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1); @@ -1081,15 +888,10 @@ void Game::LoadStuff() viewer=0; - - if(detail)kTextureSize=1024; if(detail==1)kTextureSize=512; if(detail==0)kTextureSize=256; - - - //drawmode=motionblurmode; - + //Set up distant light light.color[0]=.95; light.color[1]=.95; @@ -1111,7 +913,7 @@ void Game::LoadStuff() gravity=-10; texscale=.2/megascale/viewdistdetail; - terrain.scale=3*megascale*terraindetail*viewdistdetail; + terrain.scale=3*megascale*viewdistdetail; viewer.x=terrain.size/2*terrain.scale; viewer.z=terrain.size/2*terrain.scale; @@ -1125,7 +927,6 @@ void Game::LoadStuff() hawkcoords.z=terrain.size/2*terrain.scale-5-7; hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25; - eye.load((char *)":Data:Models:eye.solid",1); eye.Scale(.03,.03,.03); eye.CalculateNormals(0); @@ -1147,9 +948,6 @@ void Game::LoadStuff() mainmenu=0; firstload=0; - //if(targetlevel!=7) - Loadlevel(targetlevel); - rabbitcoords=player[0].coords; rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z); @@ -1165,7 +963,6 @@ void Game::LoadStuff() } } - loadscreencolor=4; LoadingScreen(); for(i=0;i