]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Terrain.cpp
some findClosest* refactoring
[lugaru.git] / Source / Terrain.cpp
index d9c73b056b320ff90bfcc49f8cadd158cbbc74f3..ecc8757b7dc953971759fb7a595eff6a1b587cd6 100644 (file)
@@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Objects.h"
 extern XYZ viewer;
 extern float viewdistance;
-extern float lightambient[3],lightbrightness[3];
 extern float fadestart;
 extern int environment;
 extern float texscale;
@@ -38,7 +37,6 @@ extern float blurness;
 extern float targetblurness;
 extern Objects objects;
 extern TGAImageRec texture;
-extern Game * pgame;
 extern bool visibleloading;
 extern bool skyboxtexture;
 extern int tutoriallevel;
@@ -401,7 +399,7 @@ bool Terrain::load(const char *fileName)
                }
        }
        texture.bpp=24;
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        texdetail=temptexdetail;
 
@@ -433,7 +431,7 @@ bool Terrain::load(const char *fileName)
                }
 
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        float slopeness;
 
@@ -442,7 +440,7 @@ bool Terrain::load(const char *fileName)
                        textureness[i][j]=-1;
                }
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
 
        for(i=0;i<size;i++){
@@ -476,7 +474,7 @@ bool Terrain::load(const char *fileName)
                        }
                }
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        for(i=0;i<size;i++){
                for(j=0;j<size;j++){
@@ -488,7 +486,7 @@ bool Terrain::load(const char *fileName)
                        }
                }
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        /*float total;
        int todivide;
@@ -598,7 +596,7 @@ bool Terrain::load(const char *fileName)
                        }
                }
        }
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        patch_size=size/subdivision;
        patch_elements=(patch_size)*(patch_size)*54;
@@ -1049,7 +1047,7 @@ void Terrain::drawdecals()
                for(i=0;i<numdecals;i++){
                        if(decaltype[i]==blooddecalfast&&decalalivetime[i]<2)decalalivetime[i]=2;
                        if((decaltype[i]==shadowdecal||decaltype[i]==shadowdecalpermanent)&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, shadowtexture);
+                               shadowtexture.bind();
                                if(!blend){
                                        blend=1;
                                        glAlphaFunc(GL_GREATER, 0.0001);
@@ -1057,7 +1055,7 @@ void Terrain::drawdecals()
                                }
                        }
                        if(decaltype[i]==footprintdecal&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, footprinttexture);
+                               footprinttexture.bind();
                                if(!blend){
                                        blend=1;
                                        glAlphaFunc(GL_GREATER, 0.0001);
@@ -1065,7 +1063,7 @@ void Terrain::drawdecals()
                                }
                        }
                        if(decaltype[i]==bodyprintdecal&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, bodyprinttexture);
+                               bodyprinttexture.bind();
                                if(!blend){
                                        blend=1;
                                        glAlphaFunc(GL_GREATER, 0.0001);
@@ -1073,7 +1071,7 @@ void Terrain::drawdecals()
                                }
                        }
                        if((decaltype[i]==blooddecal||decaltype[i]==blooddecalslow)&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, bloodtexture);
+                               bloodtexture.bind();
                                if(blend){
                                        blend=0;
                                        glAlphaFunc(GL_GREATER, 0.15);
@@ -1081,7 +1079,7 @@ void Terrain::drawdecals()
                                }
                        }
                        if((decaltype[i]==blooddecalfast)&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, bloodtexture2);
+                               bloodtexture2.bind();
                                if(blend){
                                        blend=0;
                                        glAlphaFunc(GL_GREATER, 0.15);
@@ -1460,12 +1458,12 @@ void Terrain::DoShadows()
                                        if(objects.type[l]!=treetrunktype){
                                                testpoint=terrainpoint;
                                                testpoint2=terrainpoint+lightloc*50*(1-shadowed);
-                                               if(objects.model[l].LineCheck(&testpoint,&testpoint2,&col,&objects.position[l],&objects.rotation[l])!=-1){
+                                               if(objects.model[l].LineCheck(&testpoint,&testpoint2,&col,&objects.position[l],&objects.yaw[l])!=-1){
                                                        shadowed=1-(findDistance(&terrainpoint,&col)/50);       
                                                }
                                        }
                                }
-                               if(visibleloading)pgame->LoadingScreen();
+                               if(visibleloading) Game::LoadingScreen();
                        }
                        brightness=dotproduct(&lightloc,&normals[i][j]);
                        if(shadowed)brightness*=1-shadowed;
@@ -1486,7 +1484,7 @@ void Terrain::DoShadows()
                }
        }
 
-       if(visibleloading)pgame->LoadingScreen();
+       if(visibleloading) Game::LoadingScreen();
 
        //Smooth shadows
        for(i=0;i<size;i++){
@@ -1518,13 +1516,6 @@ void Terrain::DoShadows()
 
 Terrain::Terrain()
 {
-       bloodtexture = 0;
-       bloodtexture2 = 0;
-       shadowtexture = 0;
-       footprinttexture = 0;
-       bodyprinttexture = 0;
-       breaktexture = 0;
-       terraintexture = 0;
        size = 0;
 
        memset(patchobjectnum, 0, sizeof(patchobjectnum));
@@ -1565,12 +1556,12 @@ Terrain::Terrain()
 }
 Terrain::~Terrain()
 {
-       if(terraintexture)glDeleteTextures( 1, &terraintexture );
-       if(shadowtexture) glDeleteTextures( 1, &shadowtexture );
-       if(bodyprinttexture) glDeleteTextures( 1, &bodyprinttexture );
-       if(footprinttexture) glDeleteTextures( 1, &footprinttexture );
-       if(bloodtexture) glDeleteTextures( 1, &bloodtexture );
-       if(bloodtexture2) glDeleteTextures( 1, &bloodtexture2 );
-       if(breaktexture) glDeleteTextures( 1, &breaktexture );
+       terraintexture.destroy();
+       shadowtexture.destroy();
+       bodyprinttexture.destroy();
+       footprinttexture.destroy();
+       bloodtexture.destroy();
+       bloodtexture2.destroy();
+       breaktexture.destroy();
 }