From 90a372e7d97dd17e83a02732444788cc4b8f31a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Sat, 26 Nov 2016 17:13:06 +0800 Subject: [PATCH] Cleaned up a bit clothes adding It would be even better to put the loop in Person class but the editor code is a bit special and need to be adapted a tiny bit first --- Source/ConsoleCmds.cpp | 2 +- Source/Game.h | 1 - Source/GameTick.cpp | 50 +++-------------------------------------- Source/Person.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ Source/Person.h | 3 +++ 5 files changed, 58 insertions(+), 49 deletions(-) diff --git a/Source/ConsoleCmds.cpp b/Source/ConsoleCmds.cpp index 698c73b..c31eed7 100644 --- a/Source/ConsoleCmds.cpp +++ b/Source/ConsoleCmds.cpp @@ -141,7 +141,7 @@ static void set_clothes(int pnum, const char *args) char buf[64]; snprintf(buf, 63, ":Data:Textures:%s.png", args); - if (!AddClothes(buf, &Person::players[pnum]->skeleton.skinText[0])) + if (!Person::players[pnum]->addClothes(buf)) return; Person::players[pnum]->DoMipmaps(); diff --git a/Source/Game.h b/Source/Game.h index 2765367..ce7c69f 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -149,7 +149,6 @@ int DrawGLScene(StereoSide side); void LoadMenu(); void playdialogueboxsound(); int findClosestPlayer(); -bool AddClothes(const char *fileName, GLubyte *array); void Loadlevel(int which); void Loadlevel(const char *name); void Tick(); diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 3d492fd..c66767d 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -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; @@ -1350,7 +1306,7 @@ void Game::Loadlevel(const char *name) 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]->addClothes(j); } Person::players[i]->DoMipmaps(); } @@ -2106,7 +2062,7 @@ void doDebugKeys() 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]->addClothes(i); } Person::players[closest]->DoMipmaps(); } @@ -2544,7 +2500,7 @@ void doDebugKeys() 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]); + Person::players.back()->addClothes(i); } if (Person::players.back()->numclothes) { Person::players.back()->DoMipmaps(); diff --git a/Source/Person.cpp b/Source/Person.cpp index 2f92f88..6487600 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -6533,3 +6533,54 @@ void Person::takeWeapon(int weaponId) weaponids[0] = weaponId; } +bool Person::addClothes(const int& clothesId) +{ + return addClothes(clothes[clothesId]); +} + +bool Person::addClothes(const char* fileName) +{ + LOGFUNC; + + GLubyte* array = &skeleton.skinText[0]; + + //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; + } +} diff --git a/Source/Person.h b/Source/Person.h index f98f494..801553a 100644 --- a/Source/Person.h +++ b/Source/Person.h @@ -398,6 +398,9 @@ public: void RagDoll(bool checkcollision); void takeWeapon (int weaponId); + + bool addClothes(const int& clothesId); + bool addClothes(const char* fileName); }; const int maxplayers = 10; -- 2.39.5