X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGameInitDispose.cpp;h=8c0917914c4bcb3b9b79d544503292b53f0feefc;hb=12421cc17c6176a16ec18901e02d760ccd0b28ad;hp=b2716e930732d3e76bc56f80e94bc9cb3f6d4045;hpb=8d7575ad3310c2ab6c4fba94be161954fed38559;p=lugaru.git diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index b2716e9..8c09179 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -22,12 +22,12 @@ 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; extern XYZ viewer; extern XYZ lightlocation; -extern float lightambient[3],lightbrightness[3]; extern float fadestart; extern float texscale; extern float gravity; @@ -59,7 +59,6 @@ extern TGAImageRec texture; extern short vRefNum; extern long dirID; extern int mainmenu; -extern int oldmainmenu; extern bool visibleloading; extern float flashamount,flashr,flashg,flashb; extern int flashdelay; @@ -79,8 +78,8 @@ extern int dialogueboxsound[20][20]; extern char dialoguetext[20][20][128]; extern char dialoguename[20][20][64]; extern XYZ dialoguecamera[20][20]; -extern float dialoguecamerarotation[20][20]; -extern float dialoguecamerarotation2[20][20]; +extern float dialoguecamerayaw[20][20]; +extern float dialoguecamerapitch[20][20]; extern int indialogue; extern int whichdialogue; extern float dialoguetime; @@ -98,17 +97,16 @@ void LOG(const std::string &fmt, ...) // !!! FIXME: write me. } - -void Game::Dispose() +void Dispose() { LOGFUNC; - if(endgame==2){ - accountactive->endGame(); - endgame=0; + if(Game::endgame==2){ + Game::accountactive->endGame(); + Game::endgame=0; } - Account::saveFile(":Data:Users", accountactive); + Account::saveFile(":Data:Users", Game::accountactive); //textures.clear(); @@ -134,128 +132,43 @@ void Game::Dispose() #endif } - -void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha) { - textures.push_back(TextureInfo(fileName,textureid,mipmap,hasalpha)); - textures.back().load(); +void Game::newGame(){ + text = new Text(); + skybox = new SkyBox(); } -void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize) { - textures.push_back(TextureInfo(fileName,textureid,mipmap,array,skinsize)); - textures.back().load(); +void Game::deleteGame(){ + if(skybox) + delete skybox; + if(text) + delete text; + glDeleteTextures( 10, &Mainmenuitems[0] ); + glDeleteTextures( 1, &cursortexture ); + glDeleteTextures( 1, &Maparrowtexture ); + glDeleteTextures( 1, &Mapboxtexture ); + glDeleteTextures( 1, &Mapcircletexture ); + glDeleteTextures( 1, &terraintexture ); + glDeleteTextures( 1, &terraintexture2 ); + glDeleteTextures( 1, &screentexture ); + glDeleteTextures( 1, &screentexture2 ); + glDeleteTextures( 1, &hawktexture ); + glDeleteTextures( 1, &logotexture ); + glDeleteTextures( 1, &loadscreentexture ); + + Dispose(); } -void Game::LoadTextureData(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::LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload) -{ - 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; - if(!reload) - 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) +void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize) { int i; int bytesPerPixel; @@ -294,53 +207,6 @@ void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte } } -bool Game::AddClothes(const char *fileName, GLubyte *array) -{ - int i; - int bytesPerPixel; - - LOGFUNC; - - //upload_image( fileName ); - //LoadTGA( fileName ); - //Load Image - unsigned char fileNamep[256]; - CopyCStringToPascal(fileName,fileNamep); - //Load Image - bool opened; - opened=upload_image( fileNamep ,1); - - float alphanum; - //Is it valid? - if(opened){ - if(tintr>1)tintr=1; - if(tintg>1)tintg=1; - if(tintb>1)tintb=1; - - if(tintr<0)tintr=0; - if(tintg<0)tintg=0; - if(tintb<0)tintb=0; - - bytesPerPixel=texture.bpp/8; - - int tempnum=0; - alphanum=255; - for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){ - if(bytesPerPixel==3)alphanum=255; - else if((i+1)%4==0)alphanum=texture.data[i]; - //alphanum/=2; - if((i+1)%4||bytesPerPixel==3){ - if((i%4)==0)texture.data[i]*=tintr; - if((i%4)==1)texture.data[i]*=tintg; - if((i%4)==2)texture.data[i]*=tintb; - array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255); - tempnum++; - } - } - } - else return 0; - return 1; -} //***************> ResizeGLScene() <******/ @@ -577,7 +443,7 @@ void Game::LoadingScreen() } } -void Game::FadeLoadingScreen(float howmuch) +void FadeLoadingScreen(float howmuch) { static float loadprogress; @@ -662,8 +528,6 @@ void Game::InitGame() LOGFUNC; - autocam=0; - numchallengelevels=14; accountactive=Account::loadFile(":Data:Users"); @@ -758,8 +622,8 @@ void Game::InitGame() int temptexdetail=texdetail; texdetail=1; - text.LoadFontTexture(":Data:Textures:Font.png"); - text.BuildFont(); + text->LoadFontTexture(":Data:Textures:Font.png"); + text->BuildFont(); texdetail=temptexdetail; FadeLoadingScreen(10); @@ -845,30 +709,32 @@ void Game::InitGame() stillloading=0; firstload=0; - oldmainmenu=0; newdetail=detail; newscreenwidth=screenwidth; newscreenheight=screenheight; + + LoadMenu(); } -void Game::LoadScreenTexture() { +void LoadScreenTexture() { glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); - if(!screentexture) - glGenTextures( 1, &screentexture ); + if(!Game::screentexture) + glGenTextures( 1, &Game::screentexture ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glEnable(GL_TEXTURE_2D); - glBindTexture( GL_TEXTURE_2D, screentexture); + glBindTexture( GL_TEXTURE_2D, Game::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); } +//TODO: move LoadStuff() closer to GameTick.cpp to get rid of various vars shared in Game.h void Game::LoadStuff() { static float temptexdetail; @@ -884,27 +750,19 @@ void Game::LoadStuff() stillloading=1; - //texture.data = ( GLubyte* )malloc( 1024*1024*4 ); - for(i=0;iLoadFontTexture(":Data:Textures:Font.png"); + text->BuildFont(); texdetail=temptexdetail; numsounds=71; @@ -912,10 +770,6 @@ void Game::LoadStuff() viewdistdetail=2; viewdistance=50*megascale*viewdistdetail; - brightness=100; - - - if(detail==2){ texdetail=1; } @@ -928,22 +782,9 @@ void Game::LoadStuff() realtexdetail=texdetail; - /*texdetail/=4; - if(texdetail<1)texdetail=1; - realtexdetail=texdetail*4; - */ numplayers=1; - - /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1); - - LoadTexture(":Data:Textures:rock.png",&terraintexture2,1); - - LoadTexture(":Data:Textures:detail.png",&terraintexture3,1); - */ - - LOG("Loading weapon data..."); LoadTexture(":Data:Textures:knife.png",&Weapon::knifetextureptr,0,1); @@ -983,8 +824,6 @@ void Game::LoadStuff() Weapon::staffmodel.CalculateNormals(1); //Weapon::staffmodel.ScaleNormals(-1,-1,-1); - //temptexdetail=texdetail; - //if(texdetail>4)texdetail=4; LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1); LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1); @@ -998,30 +837,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); @@ -1034,22 +854,17 @@ void Game::LoadStuff() LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1); LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1); - rotation=0; - rotation2=0; + yaw=0; + pitch=0; ReSizeGLScene(90,.01); 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; @@ -1085,7 +900,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); @@ -1107,12 +921,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); loadAllAnimations(); //Fix knife stab, too lazy to do it manually @@ -1176,7 +984,6 @@ void Game::LoadStuff() LoadingScreen(); - //if(ismotionblur){ if(!screentexture){ LoadScreenTexture(); }