]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameInitDispose.cpp
some more unused variables cleanup
[lugaru.git] / Source / GameInitDispose.cpp
index a2f93b98502158c19c4f536631f8192c48d22f9e..a0f164ad2bde461e6907cd4131e7d5aed820de6e 100644 (file)
@@ -34,13 +34,11 @@ extern float gravity;
 extern Light light;
 extern Skeleton testskeleton;
 extern int numsounds;
-extern int channels[100];
 extern Terrain terrain;
 //extern Sprites sprites;
 extern int kTextureSize;
 extern float texdetail;
 extern float realtexdetail;
-extern float terraindetail;
 extern float volume;
 extern Objects objects;
 extern int detail;
@@ -63,7 +61,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];
@@ -71,7 +68,6 @@ extern int whichjointendarray[26];
 extern int difficulty;
 extern float tintr,tintg,tintb;
 extern float slomospeed;
-extern char mapname[256];
 extern bool gamestarted;
 
 extern int numdialogues;
@@ -97,21 +93,14 @@ extern float accountcampaigntime[10];
 extern int accountcampaignchoicesmade[10];
 extern int accountcampaignchoices[10][5000];
 
-extern "C"     void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
-extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
-
 void LOG(const std::string &fmt, ...)
 {
     // !!! FIXME: write me.
 }
 
 
-Game::TextureList Game::textures;
-
 void Game::Dispose()
 {
-       int i,j;
-
        LOGFUNC;
 
        if(endgame==2){
@@ -121,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...");
 
@@ -137,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]);
        }
@@ -152,7 +135,17 @@ void Game::Dispose()
 }
 
 
-void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
+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::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::LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
 {
        GLuint          type;
 
@@ -198,7 +191,7 @@ void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool
        }
 }
 
-void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
+void Game::LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload)
 {
        GLuint          type;
        int i;
@@ -243,12 +236,12 @@ void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GL
                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++;
-                       }
-               }
+        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;
 
@@ -301,7 +294,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;
@@ -371,7 +364,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 ();
@@ -388,7 +381,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);
@@ -424,14 +416,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);
@@ -488,13 +472,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);
@@ -558,15 +535,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;
@@ -606,15 +574,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);
@@ -647,13 +613,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);
@@ -675,17 +634,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;
 }
 
 
@@ -715,8 +664,6 @@ void Game::InitGame()
 
        autocam=0;
 
-       int i,j;
-
        numchallengelevels=14;
 
        accountactive=Account::loadFile(":Data:Users");
@@ -819,20 +766,14 @@ 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;
        }
 
-       memset(channels, 0xff, sizeof(channels));
-
        LOG("Initializing sound system...");
 
     int output = -1;
@@ -873,11 +814,8 @@ void Game::InitGame()
        OPENAL_SetSFXMasterVolume((int)(volume*255));
        loadAllSounds();
 
-       if(musictoggle){
-               PlayStreamEx(stream_music3, samp[stream_music3], 0, true);
-               OPENAL_SetPaused(channels[stream_music3], false);
-               OPENAL_SetVolume(channels[stream_music3], 256);
-       }
+       if(musictoggle)
+         emit_stream_np(stream_menutheme);
 
        LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
 
@@ -896,9 +834,6 @@ void Game::InitGame()
        //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
        texdetail=temptexdetail;
 
-       loaddistrib=0;
-       anim=0;
-
        FadeLoadingScreen(95);
 
 
@@ -915,22 +850,33 @@ 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;
 
        visibleloading=1;
 
-       /*musicvolume[3]=512;
-       PlaySoundEx( music4, samp[music4], NULL, true);
-       OPENAL_SetPaused(channels[music4], false);
-       OPENAL_SetVolume(channels[music4], 512);
-       */
        loadtime=0;
 
        stillloading=1;
@@ -969,16 +915,12 @@ void Game::LoadStuff()
 
        if(detail==2){
                texdetail=1;
-               terraindetail=1;
        }
        if(detail==1){
                texdetail=2;
-               terraindetail=1;
        }
        if(detail==0){
                texdetail=4;
-               terraindetail=1;
-               //terraindetail=2;
        }
 
        realtexdetail=texdetail;
@@ -1126,7 +1068,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;
@@ -1180,7 +1122,6 @@ void Game::LoadStuff()
                }
        }
 
-       loadscreencolor=4;
        LoadingScreen();
 
        for(i=0;i<player[0].skeleton.num_joints;i++){
@@ -1189,7 +1130,6 @@ void Game::LoadStuff()
                }
        }
 
-       loadscreencolor=4;
        LoadingScreen();
 
        for(i=0;i<player[0].skeleton.num_joints;i++){
@@ -1213,13 +1153,11 @@ void Game::LoadStuff()
                        animation[swordsneakattackanim].position[i][j]+=moveamount;
                }
        }
-       loadscreencolor=4;
        LoadingScreen();
        for(j=0;j<animation[swordsneakattackanim].numframes;j++){
                animation[swordsneakattackanim].weapontarget[j]+=moveamount;
        }
 
-       loadscreencolor=4;
        LoadingScreen();
 
        for(i=0;i<player[0].skeleton.num_joints;i++){
@@ -1227,36 +1165,17 @@ void Game::LoadStuff()
                        animation[swordsneakattackedanim].position[i][j]+=moveamount;
                }
        }
-       /*
-       for(i=0;i<player[0].skeleton.num_joints;i++){
-       for(j=0;j<animation[sleepanim].numframes;j++){
-       animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
-       }
-       }
-       */
-       loadscreencolor=4;
+       
        LoadingScreen();
        temptexdetail=texdetail;
        texdetail=1;
        texdetail=temptexdetail;
 
-       loadscreencolor=4;
        LoadingScreen();
 
        //if(ismotionblur){
        if(!screentexture){
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               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);
+        LoadScreenTexture();
        }
 
        if(targetlevel!=7){