From: Côme Chilliet Date: Sat, 26 Nov 2016 12:08:43 +0000 (+0800) Subject: Moved clothes loop to Person, got rid of globals tintr,tintg,tintb X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=6df65bf46ace2c0b8753115b8c39600f307e3452;p=lugaru.git Moved clothes loop to Person, got rid of globals tintr,tintg,tintb --- diff --git a/Source/ConsoleCmds.cpp b/Source/ConsoleCmds.cpp index c31eed7..32e9c1c 100644 --- a/Source/ConsoleCmds.cpp +++ b/Source/ConsoleCmds.cpp @@ -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 */ diff --git a/Source/Game.h b/Source/Game.h index ce7c69f..c5f37cb 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -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, diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index 79a6a8d..05c7e19 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -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; diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index c66767d..11571d6 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -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; diff --git a/Source/Globals.cpp b/Source/Globals.cpp index 2d3da97..78d8098 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -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; diff --git a/Source/Person.cpp b/Source/Person.cpp index 6487600..330dd40 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -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; diff --git a/Source/Person.h b/Source/Person.h index 801553a..2f0a6ca 100644 --- a/Source/Person.h +++ b/Source/Person.h @@ -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;