]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Objects/Object.cpp
Added braces to all statements with clang-tidy and ran clang-format again
[lugaru.git] / Source / Objects / Object.cpp
index 796e6ef16f222009ba01f3d53d667099463938b8..081f23de9686df7fea95b21a5c034f41948c0b2c 100644 (file)
@@ -47,30 +47,31 @@ Texture Object::rocktextureptr;
 
 //Functions
 
-Object::Object() :
-    position(),
-    type(boxtype),
-    yaw(0),
-    pitch(0),
-    rotx(0),
-    rotxvel(0),
-    roty(0),
-    rotyvel(0),
-    possible(false),
-    model(),
-    displaymodel(),
-    friction(0),
-    scale(0),
-    messedwith(0),
-    checked(0),
-    shadowed(0),
-    occluded(0),
-    onfire(false),
-    flamedelay(0)
+Object::Object()
+    : position()
+    , type(boxtype)
+    , yaw(0)
+    , pitch(0)
+    , rotx(0)
+    , rotxvel(0)
+    , roty(0)
+    , rotyvel(0)
+    , possible(false)
+    , model()
+    , displaymodel()
+    , friction(0)
+    , scale(0)
+    , messedwith(0)
+    , checked(0)
+    , shadowed(0)
+    , occluded(0)
+    , onfire(false)
+    flamedelay(0)
 {
 }
 
-Object::Object(object_type _type, XYZ _position, float _yaw, float _pitch, float _scale) : Object()
+Object::Object(object_type _type, XYZ _position, float _yaw, float _pitch, float _scale)
+    : Object()
 {
     scale = _scale;
     type = _type;
@@ -78,7 +79,7 @@ Object::Object(object_type _type, XYZ _position, float _yaw, float _pitch, float
     yaw = _yaw;
     pitch = _pitch;
 
-    switch(type) {
+    switch (type) {
         case boxtype:
             model.loaddecal("Models/Box.solid");
             friction = 1.5;
@@ -206,15 +207,13 @@ void Object::doShadows(XYZ lightloc)
             patchx = terrainpoint.x / (terrain.size / subdivision * terrain.scale);
             patchz = terrainpoint.z / (terrain.size / subdivision * terrain.scale);
             if (patchx >= 0 && patchz >= 0 && patchx < subdivision && patchz < subdivision) {
-                if (terrain.patchobjectnum[patchx][patchz]) {
-                    for (int k = 0; k < terrain.patchobjectnum[patchx][patchz]; k++) {
-                        int l = terrain.patchobjects[patchx][patchz][k];
-                        if (objects[l]->type != treetrunktype) {
-                            testpoint = terrainpoint;
-                            testpoint2 = terrainpoint + lightloc * 50 * (1 - shadowed);
-                            if (objects[l]->model.LineCheck(&testpoint, &testpoint2, &col, &objects[l]->position, &objects[l]->yaw) != -1) {
-                                shadowed = 1 - (findDistance(&terrainpoint, &col) / 50);
-                            }
+                for (unsigned int k = 0; k < terrain.patchobjects[patchx][patchz].size(); k++) {
+                    unsigned int l = terrain.patchobjects[patchx][patchz][k];
+                    if (objects[l]->type != treetrunktype) {
+                        testpoint = terrainpoint;
+                        testpoint2 = terrainpoint + lightloc * 50 * (1 - shadowed);
+                        if (objects[l]->model.LineCheck(&testpoint, &testpoint2, &col, &objects[l]->position, &objects[l]->yaw) != -1) {
+                            shadowed = 1 - (findDistance(&terrainpoint, &col) / 50);
                         }
                     }
                 }
@@ -252,30 +251,58 @@ void Object::handleRot(int divide)
 {
     messedwith -= multiplier;
     if (rotxvel || rotx) {
-        if (rotx > 0) rotxvel -= multiplier * 8 * fabs(rotx);
-        if (rotx < 0) rotxvel += multiplier * 8 * fabs(rotx);
-        if (rotx > 0) rotxvel -= multiplier * 4;
-        if (rotx < 0) rotxvel += multiplier * 4;
-        if (rotxvel > 0) rotxvel -= multiplier * 4;
-        if (rotxvel < 0) rotxvel += multiplier * 4;
-        if (fabs(rotx) < multiplier * 4)
+        if (rotx > 0) {
+            rotxvel -= multiplier * 8 * fabs(rotx);
+        }
+        if (rotx < 0) {
+            rotxvel += multiplier * 8 * fabs(rotx);
+        }
+        if (rotx > 0) {
+            rotxvel -= multiplier * 4;
+        }
+        if (rotx < 0) {
+            rotxvel += multiplier * 4;
+        }
+        if (rotxvel > 0) {
+            rotxvel -= multiplier * 4;
+        }
+        if (rotxvel < 0) {
+            rotxvel += multiplier * 4;
+        }
+        if (fabs(rotx) < multiplier * 4) {
             rotx = 0;
-        if (fabs(rotxvel) < multiplier * 4)
+        }
+        if (fabs(rotxvel) < multiplier * 4) {
             rotxvel = 0;
+        }
 
         rotx += rotxvel * multiplier * 4;
     }
     if (rotyvel || roty) {
-        if (roty > 0) rotyvel -= multiplier * 8 * fabs(roty);
-        if (roty < 0) rotyvel += multiplier * 8 * fabs(roty);
-        if (roty > 0) rotyvel -= multiplier * 4;
-        if (roty < 0) rotyvel += multiplier * 4;
-        if (rotyvel > 0) rotyvel -= multiplier * 4;
-        if (rotyvel < 0) rotyvel += multiplier * 4;
-        if (fabs(roty) < multiplier * 4)
+        if (roty > 0) {
+            rotyvel -= multiplier * 8 * fabs(roty);
+        }
+        if (roty < 0) {
+            rotyvel += multiplier * 8 * fabs(roty);
+        }
+        if (roty > 0) {
+            rotyvel -= multiplier * 4;
+        }
+        if (roty < 0) {
+            rotyvel += multiplier * 4;
+        }
+        if (rotyvel > 0) {
+            rotyvel -= multiplier * 4;
+        }
+        if (rotyvel < 0) {
+            rotyvel += multiplier * 4;
+        }
+        if (fabs(roty) < multiplier * 4) {
             roty = 0;
-        if (fabs(rotyvel) < multiplier * 4)
+        }
+        if (fabs(rotyvel) < multiplier * 4) {
             rotyvel = 0;
+        }
 
         roty += rotyvel * multiplier * 4;
     }
@@ -285,14 +312,18 @@ void Object::handleRot(int divide)
     if (rotx) {
         glRotatef(-rotx / divide, 0, 0, 1);
     }
-    if (rotx > 10)
+    if (rotx > 10) {
         rotx = 10;
-    if (rotx < -10)
+    }
+    if (rotx < -10) {
         rotx = -10;
-    if (roty > 10)
+    }
+    if (roty > 10) {
         roty = 10;
-    if (roty < -10)
+    }
+    if (roty < -10) {
         roty = -10;
+    }
 }
 
 void Object::draw()
@@ -310,22 +341,25 @@ void Object::draw()
         hidden = !(distsqflat(&viewer, &position) > playerdist + 3 || (type != bushtype && type != treeleavestype));
         if (!hidden) {
 
-            if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment)
-                glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness );
-            else
-                glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+            if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment) {
+                glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness);
+            } else {
+                glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
+            }
             distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
-            if (distance > 1)
+            if (distance > 1) {
                 distance = 1;
+            }
             if (distance > 0) {
 
                 if (occluded < 6) {
                     glMatrixMode(GL_MODELVIEW);
                     glPushMatrix();
-                    if (!model.color)
+                    if (!model.color) {
                         glEnable(GL_LIGHTING);
-                    else
+                    } else {
                         glDisable(GL_LIGHTING);
+                    }
                     glDepthMask(1);
                     glTranslatef(position.x, position.y, position.z);
                     if (type == bushtype) {
@@ -563,15 +597,15 @@ void Object::AddObjectsToTerrain()
     }
 }
 
-void Object::SphereCheckPossible(XYZ *p1, float radius)
+void Object::SphereCheckPossible(XYZp1, float radius)
 {
     int whichpatchx = p1->x / (terrain.size / subdivision * terrain.scale);
     int whichpatchz = p1->z / (terrain.size / subdivision * terrain.scale);
 
     if (whichpatchx >= 0 && whichpatchz >= 0 && whichpatchx < subdivision && whichpatchz < subdivision) {
-        if (terrain.patchobjectnum[whichpatchx][whichpatchz] > 0 && terrain.patchobjectnum[whichpatchx][whichpatchz] < 500) {
-            for (int j = 0; j < terrain.patchobjectnum[whichpatchx][whichpatchz]; j++) {
-                int i = terrain.patchobjects[whichpatchx][whichpatchz][j];
+        if (terrain.patchobjects[whichpatchx][whichpatchz].size() < 500) {
+            for (unsigned int j = 0; j < terrain.patchobjects[whichpatchx][whichpatchz].size(); j++) {
+                unsigned int i = terrain.patchobjects[whichpatchx][whichpatchz][j];
                 objects[i]->possible = false;
                 if (objects[i]->model.SphereCheckPossible(p1, radius, &objects[i]->position, &objects[i]->yaw) != -1) {
                     objects[i]->possible = true;
@@ -587,12 +621,12 @@ void Object::Draw()
         objects[i]->draw();
     }
 
-    glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+    glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
     for (unsigned i = 0; i < objects.size(); i++) {
         objects[i]->drawSecondPass();
     }
     if (environment == desertenvironment) {
-        glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
+        glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
     }
     glEnable(GL_ALPHA_TEST);
     SetUpLight(&light, 0);
@@ -623,8 +657,9 @@ void Object::DoShadows()
 {
     XYZ lightloc;
     lightloc = light.location;
-    if (!skyboxtexture)
+    if (!skyboxtexture) {
         lightloc = 0;
+    }
     lightloc.y += 10;
     Normalise(&lightloc);
 
@@ -646,7 +681,7 @@ int Object::checkcollide(XYZ startpoint, XYZ endpoint)
 
     for (unsigned int i = 0; i < objects.size(); i++) {
         if (checkcollide(startpoint, endpoint, i, minx, miny, minz, maxx, maxy, maxz) != -1) {
-            return (int) i;
+            return (int)i;
         }
     }
 
@@ -676,15 +711,15 @@ int Object::checkcollide(XYZ startpoint, XYZ endpoint, int what, float minx, flo
             return what;
         }
     } else {
-        if (     objects[what]->position.x > minx - objects[what]->model.boundingsphereradius &&
-                 objects[what]->position.x < maxx + objects[what]->model.boundingsphereradius &&
-                 objects[what]->position.y > miny - objects[what]->model.boundingsphereradius &&
-                 objects[what]->position.y < maxy + objects[what]->model.boundingsphereradius &&
-                 objects[what]->position.z > minz - objects[what]->model.boundingsphereradius &&
-                 objects[what]->position.z < maxz + objects[what]->model.boundingsphereradius) {
-            if (     objects[what]->type != treeleavestype &&
-                     objects[what]->type != bushtype &&
-                     objects[what]->type != firetype) {
+        if (objects[what]->position.x > minx - objects[what]->model.boundingsphereradius &&
+            objects[what]->position.x < maxx + objects[what]->model.boundingsphereradius &&
+            objects[what]->position.y > miny - objects[what]->model.boundingsphereradius &&
+            objects[what]->position.y < maxy + objects[what]->model.boundingsphereradius &&
+            objects[what]->position.z > minz - objects[what]->model.boundingsphereradius &&
+            objects[what]->position.z < maxz + objects[what]->model.boundingsphereradius) {
+            if (objects[what]->type != treeleavestype &&
+                objects[what]->type != bushtype &&
+                objects[what]->type != firetype) {
                 colviewer = startpoint;
                 coltarget = endpoint;
                 if (objects[what]->model.LineCheck(&colviewer, &coltarget, &colpoint, &objects[what]->position, &objects[what]->yaw) != -1) {
@@ -699,8 +734,8 @@ int Object::checkcollide(XYZ startpoint, XYZ endpoint, int what, float minx, flo
 
 //~ Object::~Objects()
 //~ {
-    //~ boxtextureptr.destroy();
-    //~ treetextureptr.destroy();
-    //~ bushtextureptr.destroy();
-    //~ rocktextureptr.destroy();
+//~ boxtextureptr.destroy();
+//~ treetextureptr.destroy();
+//~ bushtextureptr.destroy();
+//~ rocktextureptr.destroy();
 //~ }