]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameDraw.cpp
Cleaned a bit flashing by using a function
[lugaru.git] / Source / GameDraw.cpp
index 56fa29ee4cbce68f5e469018b9593788891b2a83..4994b1184b92c6b72763d7c694660bba05fe65d0 100644 (file)
@@ -1,22 +1,21 @@
 /*
 Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
 
 This file is part of Lugaru.
 
-Lugaru is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
+Lugaru is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-See the GNU General Public License for more details.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "Game.h"
@@ -30,9 +29,7 @@ extern int environment;
 extern float texscale;
 extern Light light;
 extern Terrain terrain;
-//extern Sprites sprites;
 extern float multiplier;
-extern float sps;
 extern float viewdistance;
 extern float fadestart;
 extern float screenwidth, screenheight;
@@ -42,7 +39,6 @@ extern Light light;
 extern Objects objects;
 extern int detail;
 extern float usermousesensitivity;
-extern bool osx;
 extern float camerashake;
 extern int slomo;
 extern float slomodelay;
@@ -63,20 +59,12 @@ extern int netstate;
 extern float motionbluramount;
 extern bool isclient;
 extern bool alwaysblur;
-extern int test;
-extern bool tilt2weird;
-extern bool tiltweird;
-extern bool midweird;
-extern bool proportionweird;
-extern bool vertexweird[6];
 extern bool velocityblur;
 extern bool debugmode;
 extern int mainmenu;
 extern int bloodtoggle;
 extern int difficulty;
 extern bool decals;
-// MODIFIED GWC
-//extern int texdetail;
 extern float texdetail;
 extern bool musictoggle;
 extern int tutoriallevel;
@@ -99,8 +87,6 @@ extern int currenthotspot;;
 extern bool campaign;
 extern bool winfreeze;
 
-extern float menupulse;
-
 extern bool gamestart;
 
 extern bool gamestarted;
@@ -121,13 +107,13 @@ enum drawmodes {
     realmotionblurmode, doublevisionmode, glowmode,
 };
 
-void Game::flash()   // shouldn't be that way, these should be attributes and Person class should not change rendering.
+void Game::flash(float amount, int delay)   // shouldn't be that way, these should be attributes and Person class should not change rendering.
 {
     flashr = 1;
     flashg = 0;
     flashb = 0;
-    flashamount = 1;
-    flashdelay = 1;
+    flashamount = amount;
+    flashdelay = delay;
 }
 
 void DrawMenu();
@@ -232,16 +218,6 @@ int Game::DrawGLScene(StereoSide side)
         if (winfreeze || mainmenu)
             drawmode = normalmode;
 
-#if PLATFORM_MACOSX
-        if (drawmode == glowmode) {
-            RGBColor color2;
-            color2.red = 0;
-            color2.green = 0;
-            color2.blue = 0;
-            DSpContext_FadeGamma(NULL, 200, &color2);
-        }
-#endif
-
         if (drawtoggle != 2)
             drawtoggle = 1 - drawtoggle;
 
@@ -264,7 +240,6 @@ int Game::DrawGLScene(StereoSide side)
         glDrawBuffer(GL_BACK);
         glReadBuffer(GL_BACK);
 
-        //glFinish();
         static XYZ terrainlight;
         static float distance;
         if (drawmode == normalmode)
@@ -418,9 +393,6 @@ int Game::DrawGLScene(StereoSide side)
         terrain.draw(0);
         terraintexture2.bind();
         terrain.draw(1);
-        //glBindTexture( GL_TEXTURE_2D, terraintexture3);
-        //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-        //terrain.draw(2);
 
         terrain.drawdecals();
 
@@ -433,18 +405,6 @@ int Game::DrawGLScene(StereoSide side)
 
         glEnable(GL_COLOR_MATERIAL);
 
-        test = 2;
-        tilt2weird = 0;
-        tiltweird = 0;
-        midweird = 0;
-        proportionweird = 0;
-        vertexweird[0] = 0;
-        vertexweird[1] = 0;
-        vertexweird[2] = 0;
-        vertexweird[3] = 0;
-        vertexweird[4] = 0;
-        vertexweird[5] = 0;
-
         if (!cellophane) {
             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
             glEnable(GL_CULL_FACE);
@@ -463,10 +423,10 @@ int Game::DrawGLScene(StereoSide side)
                     if (distance >= .5) {
                         checkpoint = DoRotation(Person::players[k]->skeleton.joints[abs(Random() % Person::players[k]->skeleton.num_joints)].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
                         checkpoint.y += 1;
-                        int i;
-                        if (!Person::players[k]->occluded == 0)
+                        int i = -1;
+                        if (Person::players[k]->occluded != 0)
                             i = checkcollide(viewer, checkpoint, Person::players[k]->lastoccluded);
-                        if (i == -1 || Person::players[k]->occluded == 0)
+                        if (i == -1)
                             i = checkcollide(viewer, checkpoint);
                         if (i != -1) {
                             Person::players[k]->occluded += 1;
@@ -528,10 +488,10 @@ int Game::DrawGLScene(StereoSide side)
                 if (distance >= .5) {
                     checkpoint = DoRotation(Person::players[k]->skeleton.joints[abs(Random() % Person::players[k]->skeleton.num_joints)].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
                     checkpoint.y += 1;
-                    int i;
-                    if (!Person::players[k]->occluded == 0)
+                    int i = -1;
+                    if (Person::players[k]->occluded != 0)
                         i = checkcollide(viewer, checkpoint, Person::players[k]->lastoccluded);
-                    if (i == -1 || Person::players[k]->occluded == 0)
+                    if (i == -1)
                         i = checkcollide(viewer, checkpoint);
                     if (i != -1) {
                         Person::players[k]->occluded += 1;
@@ -930,13 +890,12 @@ int Game::DrawGLScene(StereoSide side)
                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
             }
-            //Hot spots
 
+            //Hot spots
             if (numhotspots && (bonustime >= 1 || bonus <= 0 || bonustime < 0) && !tutoriallevel) {
-                int closest = -1;
                 float closestdist = -1;
                 float distance = 0;
-                closest = currenthotspot;
+                int closest = currenthotspot;
                 for (int i = 0; i < numhotspots; i++) {
                     distance = distsq(&Person::players[0]->coords, &hotspot[i]);
                     if (closestdist == -1 || distance < closestdist) {
@@ -1500,11 +1459,9 @@ int Game::DrawGLScene(StereoSide side)
 
             float maxdistance = 0;
             float tempdist;
-            //~ int whichclosest;
             for (int i = 0; i < objects.numobjects; i++) {
                 tempdist = distsq(&center, &objects.position[i]);
                 if (tempdist > maxdistance) {
-                    //~ whichclosest=i;
                     maxdistance = tempdist;
                 }
             }
@@ -1512,13 +1469,10 @@ int Game::DrawGLScene(StereoSide side)
                 if (!Person::players[i]->dead) {
                     tempdist = distsq(&center, &Person::players[i]->coords);
                     if (tempdist > maxdistance) {
-                        //~ whichclosest=i;
                         maxdistance = tempdist;
                     }
                 }
             }
-            radius = fast_sqrt(maxdistance);
-
             radius = 110;
 
             glScalef(.25 / radius * 256 * terrain.scale * .4, .25 / radius * 256 * terrain.scale * .4, 1);
@@ -1685,7 +1639,6 @@ int Game::DrawGLScene(StereoSide side)
                 text->glPrint(1024 / 2 - 90, 768 / 2, string, 1, 2, 1024, 768);
             }
             loading = 2;
-            //if(ismotionblur)drawmode=motionblurmode;
             drawmode = normalmode;
         }
 
@@ -1772,7 +1725,6 @@ int Game::DrawGLScene(StereoSide side)
                     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
                     GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
                     glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
-                    //glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_SUBTRACT);
                     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
                     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT);
                     glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
@@ -1800,7 +1752,6 @@ int Game::DrawGLScene(StereoSide side)
                     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
                 }
             }
-            //glFlush();
         }
 
         glClear(GL_DEPTH_BUFFER_BIT);
@@ -1837,7 +1788,6 @@ int Game::DrawGLScene(StereoSide side)
             if (drawmode == motionblurmode) {
                 if (motionbluramount < .2)
                     motionbluramount = .2;
-                //glColor4f(1,1,1,fast_sqrt(multiplier)*2.9*motionbluramount);
                 glColor4f(1, 1, 1, motionbluramount);
                 glPushMatrix();
                 glBegin(GL_QUADS);
@@ -1986,7 +1936,6 @@ int Game::DrawGLScene(StereoSide side)
             }
             if (drawmode == radialzoommode) {
                 for (int i = 0; i < 3; i++) {
-                    //glRotatef((float)i*.1,0,0,1);
                     glColor4f(1, 1, 1, 1 / ((float)i + 1));
                     glPushMatrix();
                     glScalef(1 + (float)i * .01, 1 + (float)i * .01, 1);
@@ -2048,17 +1997,14 @@ int Game::DrawGLScene(StereoSide side)
         multiplier = 0;
     }
 
-    //glFlush();
     if ( side == stereoRight || side == stereoCenter ) {
         if (drawmode != motionblurmode || mainmenu) {
             swap_gl_buffers();
         }
     }
 
-    //myassert(glGetError() == GL_NO_ERROR);
     glDrawBuffer(GL_BACK);
     glReadBuffer(GL_BACK);
-    //glFlush();
 
     weapons.DoStuff();
 
@@ -2180,7 +2126,6 @@ void DrawMenu()
         glColor4f(1, 1, 1, 1);
         Game::cursortexture.bind();
         glPushMatrix();
-        //glScalef(.25,.25,.25);
         glBegin(GL_QUADS);
         glTexCoord2f(0, 0);
         glVertex3f(-1, -1, 0.0f);