]> git.jsancho.org Git - lugaru.git/commitdiff
Moved clothes loop to Person, got rid of globals tintr,tintg,tintb
authorCôme Chilliet <come@chilliet.eu>
Sat, 26 Nov 2016 12:08:43 +0000 (20:08 +0800)
committerCôme Chilliet <come@chilliet.eu>
Sat, 26 Nov 2016 12:08:43 +0000 (20:08 +0800)
Source/ConsoleCmds.cpp
Source/Game.h
Source/GameInitDispose.cpp
Source/GameTick.cpp
Source/Globals.cpp
Source/Person.cpp
Source/Person.h

index c31eed784b3ed3fe03e56a5dca669574979d46d5..32e9c1cb6a8a3f174f48a52bb39a2177c53c14e1 100644 (file)
@@ -70,6 +70,8 @@ extern float viewdistance;
 
 extern int whichlevel;
 
+float tintr = 1, tintg = 1, tintb = 1;
+
 /* Helpers used in console commands */
 
 /* Return true if PFX is a prefix of STR (case-insensitive).  */
@@ -141,15 +143,17 @@ static void set_clothes(int pnum, const char *args)
     char buf[64];
     snprintf(buf, 63, ":Data:Textures:%s.png", args);
 
-    if (!Person::players[pnum]->addClothes(buf))
+    int id = Person::players[pnum]->numclothes;
+    strcpy(Person::players[pnum]->clothes[id], buf);
+    Person::players[pnum]->clothestintr[id] = tintr;
+    Person::players[pnum]->clothestintg[id] = tintg;
+    Person::players[pnum]->clothestintb[id] = tintb;
+    Person::players[pnum]->numclothes++;
+
+    if (!Person::players[pnum]->addClothes(id))
         return;
 
     Person::players[pnum]->DoMipmaps();
-    strcpy(Person::players[pnum]->clothes[Person::players[pnum]->numclothes], buf);
-    Person::players[pnum]->clothestintr[Person::players[pnum]->numclothes] = tintr;
-    Person::players[pnum]->clothestintg[Person::players[pnum]->numclothes] = tintg;
-    Person::players[pnum]->clothestintb[Person::players[pnum]->numclothes] = tintb;
-    Person::players[pnum]->numclothes++;
 }
 
 /* Console commands themselves */
index ce7c69f3f7dff01a59224f3ce96ffee55f81a5be..c5f37cb7310c0f2c6a53ee5c92baa941cd1e7c5a 100644 (file)
@@ -215,7 +215,6 @@ extern int whichdialogue;
 extern int directing;
 extern float dialoguetime;
 extern int dialoguegonethrough[20];
-extern float tintr, tintg, tintb;
 
 enum maptypes {
     mapkilleveryone, mapgosomewhere,
index 79a6a8de030f85980efbef4bff5d2f3aadcb8ab6..05c7e196fbdfd38d549e7231a98d97394d8bf46b 100644 (file)
@@ -61,7 +61,6 @@ extern int flashdelay;
 extern int whichjointstartarray[26];
 extern int whichjointendarray[26];
 extern int difficulty;
-extern float tintr, tintg, tintb;
 extern float slomospeed;
 extern bool gamestarted;
 
@@ -479,10 +478,6 @@ void Game::InitGame()
 
     accountactive = Account::loadFile(":Data:Users");
 
-    tintr = 1;
-    tintg = 1;
-    tintb = 1;
-
     whichjointstartarray[0] = righthip;
     whichjointendarray[0] = rightfoot;
 
index c66767df4012221c9b61621ad4b245160bb8cda5..11571d612dea0b756ded2b87078551c8a1cf8626 100644 (file)
@@ -1301,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];
-                    Person::players[i]->addClothes(j);
-                }
-                Person::players[i]->DoMipmaps();
-            }
+            Person::players[i]->addClothes();
 
             Person::players[i]->animCurrent = bounceidleanim;
             Person::players[i]->animTarget = bounceidleanim;
@@ -2057,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];
-                    Person::players[closest]->addClothes(i);
-                }
-                Person::players[closest]->DoMipmaps();
-            }
+            Person::players[closest]->addClothes();
         }
 
         if (Input::isKeyPressed(SDL_SCANCODE_O) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
@@ -2491,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];
-                        Person::players.back()->addClothes(i);
-                    }
-                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;
index 2d3da97cb6ce681eb10963ba4b1c3491995ff4a6..78d8098471bd2a10ab198a2990924983664f842a 100644 (file)
@@ -53,7 +53,6 @@ float windvar = 0;
 float precipdelay = 0;
 float gamespeed = 0;
 float oldgamespeed = 0;
-float tintr = 0, tintg = 0, tintb = 0;
 int difficulty = 0;
 float multiplier = 0;
 float realmultiplier = 0;
index 64876000e106b9879a446549b3a038b7490dc8b4..330dd40fb9f0e415bd9fe9f58defb676b6ffeb82 100644 (file)
@@ -6533,14 +6533,20 @@ void Person::takeWeapon(int weaponId)
     weaponids[0] = weaponId;
 }
 
-bool Person::addClothes(const int& clothesId)
+void Person::addClothes()
 {
-    return addClothes(clothes[clothesId]);
+    if (numclothes > 0) {
+        for (int i = 0; i < numclothes; i++) {
+            addClothes(i);
+        }
+        DoMipmaps();
+    }
 }
 
-bool Person::addClothes(const char* fileName)
+bool Person::addClothes(const int& clothesId)
 {
     LOGFUNC;
+    const char* fileName = clothes[clothesId];
 
     GLubyte* array = &skeleton.skinText[0];
 
@@ -6551,6 +6557,10 @@ bool Person::addClothes(const char* fileName)
     float alphanum;
     //Is it valid?
     if (opened) {
+        float tintr = clothestintr[clothesId];
+        float tintg = clothestintg[clothesId];
+        float tintb = clothestintb[clothesId];
+
         if (tintr > 1) tintr = 1;
         if (tintg > 1) tintg = 1;
         if (tintb > 1) tintb = 1;
index 801553a394e363e83515e7ab37da14df5e0a3f38..2f0a6ca982b5482f973f192956ab036f064f62b6 100644 (file)
@@ -400,7 +400,7 @@ public:
     void takeWeapon (int weaponId);
 
     bool addClothes(const int& clothesId);
-    bool addClothes(const char* fileName);
+    void addClothes();
 };
 
 const int maxplayers = 10;