]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
Moved clothes loop to Person, got rid of globals tintr,tintg,tintb
[lugaru.git] / Source / GameTick.cpp
index 3d492fdaeae50c54b6d6e4c59421b24017106132..11571d612dea0b756ded2b87078551c8a1cf8626 100644 (file)
@@ -383,50 +383,6 @@ void Game::playdialogueboxsound()
 
 // ================================================================
 
-bool Game::AddClothes(const char *fileName, GLubyte *array)
-{
-    LOGFUNC;
-    //Load Image
-    ImageRec texture;
-    bool opened = load_image(fileName, texture);
-
-    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;
-
-        int bytesPerPixel = texture.bpp / 8;
-
-        int tempnum = 0;
-        alphanum = 255;
-        for (int 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];
-            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++;
-            }
-        }
-        return 1;
-    } else {
-        return 0;
-    }
-}
-
 int Game::findClosestPlayer()
 {
     int closest = -1;
@@ -1345,15 +1301,7 @@ void Game::Loadlevel(const char *name)
 
             Person::players[i]->skeleton.drawmodel.textureptr.load(creatureskin[Person::players[i]->creature][Person::players[i]->whichskin], 1, &Person::players[i]->skeleton.skinText[0], &Person::players[i]->skeleton.skinsize);
 
-            if (Person::players[i]->numclothes) {
-                for (int j = 0; j < Person::players[i]->numclothes; j++) {
-                    tintr = Person::players[i]->clothestintr[j];
-                    tintg = Person::players[i]->clothestintg[j];
-                    tintb = Person::players[i]->clothestintb[j];
-                    AddClothes((char *)Person::players[i]->clothes[j], &Person::players[i]->skeleton.skinText[0]);
-                }
-                Person::players[i]->DoMipmaps();
-            }
+            Person::players[i]->addClothes();
 
             Person::players[i]->animCurrent = bounceidleanim;
             Person::players[i]->animTarget = bounceidleanim;
@@ -2101,15 +2049,7 @@ void doDebugKeys()
                         &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize);
             }
 
-            if (Person::players[closest]->numclothes) {
-                for (int i = 0; i < Person::players[closest]->numclothes; i++) {
-                    tintr = Person::players[closest]->clothestintr[i];
-                    tintg = Person::players[closest]->clothestintg[i];
-                    tintb = Person::players[closest]->clothestintb[i];
-                    AddClothes((char *)Person::players[closest]->clothes[i], &Person::players[closest]->skeleton.skinText[0]);
-                }
-                Person::players[closest]->DoMipmaps();
-            }
+            Person::players[closest]->addClothes();
         }
 
         if (Input::isKeyPressed(SDL_SCANCODE_O) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
@@ -2535,20 +2475,13 @@ void doDebugKeys()
                 Person::players.back()->immobile = Person::players[0]->immobile;
 
                 Person::players.back()->numclothes = Person::players[0]->numclothes;
-                if (Person::players.back()->numclothes)
-                    for (int i = 0; i < Person::players.back()->numclothes; i++) {
-                        strcpy(Person::players.back()->clothes[i], Person::players[0]->clothes[i]);
-                        Person::players.back()->clothestintr[i] = Person::players[0]->clothestintr[i];
-                        Person::players.back()->clothestintg[i] = Person::players[0]->clothestintg[i];
-                        Person::players.back()->clothestintb[i] = Person::players[0]->clothestintb[i];
-                        tintr = Person::players.back()->clothestintr[i];
-                        tintg = Person::players.back()->clothestintg[i];
-                        tintb = Person::players.back()->clothestintb[i];
-                        AddClothes((char *)Person::players.back()->clothes[i], &Person::players.back()->skeleton.skinText[0]);
-                    }
-                if (Person::players.back()->numclothes) {
-                    Person::players.back()->DoMipmaps();
+                for (int i = 0; i < Person::players.back()->numclothes; i++) {
+                    strcpy(Person::players.back()->clothes[i], Person::players[0]->clothes[i]);
+                    Person::players.back()->clothestintr[i] = Person::players[0]->clothestintr[i];
+                    Person::players.back()->clothestintg[i] = Person::players[0]->clothestintg[i];
+                    Person::players.back()->clothestintb[i] = Person::players[0]->clothestintb[i];
                 }
+                Person::players.back()->addClothes();
 
                 Person::players.back()->power = Person::players[0]->power;
                 Person::players.back()->speedmult = Person::players[0]->speedmult;