From 7de3125ca72d91329f0d4d0980635cf7355c3082 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Thu, 24 Nov 2016 00:08:17 +0800 Subject: [PATCH] Fixed lots of errors spotted by cppcheck --- Source/Account.cpp | 22 ++- Source/Account.h | 6 +- Source/Animation.h | 1 - Source/GameDraw.cpp | 5 +- Source/GameInitDispose.cpp | 24 +-- Source/GameTick.cpp | 4 +- Source/MacCompatibility.cpp | 4 +- Source/Objects.cpp | 284 ++++++++++++++++++------------------ Source/Person.cpp | 5 +- Source/Skeleton.cpp | 21 ++- Source/Sprite.cpp | 4 +- Source/Terrain.cpp | 31 +--- 12 files changed, 185 insertions(+), 226 deletions(-) diff --git a/Source/Account.cpp b/Source/Account.cpp index a42e2f7..1ee3242 100644 --- a/Source/Account.cpp +++ b/Source/Account.cpp @@ -30,9 +30,8 @@ extern bool debugmode; vector Account::accounts = vector(); -Account::Account(string n) : campaignProgress() +Account::Account(const string& name) : name(name), campaignProgress() { - name = string(n); difficulty = 0; progress = 0; points = 0; @@ -43,12 +42,12 @@ Account::Account(string n) : campaignProgress() setCurrentCampaign("main"); } -void Account::setCurrentCampaign(string name) +void Account::setCurrentCampaign(const string& name) { currentCampaign = name; } -Account* Account::add(string name) +Account* Account::add(const string& name) { accounts.push_back(new Account(name)); return accounts.back(); @@ -196,7 +195,6 @@ Account* Account::loadFile(string filename) void Account::saveFile(string filename, Account* accountactive) { FILE *tfile; - unsigned j; tfile = fopen(ConvertFileName(filename.c_str(), "wb"), "wb" ); if (tfile) { @@ -212,9 +210,9 @@ void Account::saveFile(string filename, Account* accountactive) fpackf(tfile, "Bi", a->campaignProgress.size()); map::const_iterator it; - for ( it = a->campaignProgress.begin(); it != a->campaignProgress.end(); ++it) { + for (it = a->campaignProgress.begin(); it != a->campaignProgress.end(); ++it) { fpackf(tfile, "Bi", it->first.size()); - for (j = 0; j < it->first.size(); j++) { + for (unsigned j = 0; j < it->first.size(); j++) { fpackf(tfile, "Bb", it->first[j]); } fpackf(tfile, "Bf", it->second.time); @@ -222,26 +220,26 @@ void Account::saveFile(string filename, Account* accountactive) fpackf(tfile, "Bf", it->second.fasttime); fpackf(tfile, "Bf", it->second.highscore); fpackf(tfile, "Bi", it->second.choices.size()); - for (j = 0; j < it->second.choices.size(); j++) { + for (unsigned j = 0; j < it->second.choices.size(); j++) { fpackf(tfile, "Bi", it->second.choices[j]); } } fpackf(tfile, "Bi", a->getCurrentCampaign().size()); - for (j = 0; j < a->getCurrentCampaign().size(); j++) { + for (unsigned j = 0; j < a->getCurrentCampaign().size(); j++) { fpackf(tfile, "Bb", a->getCurrentCampaign()[j]); } fpackf(tfile, "Bf", a->points); - for (j = 0; j < 50; j++) { + for (unsigned j = 0; j < 50; j++) { fpackf(tfile, "Bf", a->highscore[j]); fpackf(tfile, "Bf", a->fasttime[j]); } - for (j = 0; j < 60; j++) { + for (unsigned j = 0; j < 60; j++) { fpackf(tfile, "Bb", a->unlocked[j]); } fpackf(tfile, "Bi", a->name.size()); - for (j = 0; j < a->name.size(); j++) { + for (unsigned j = 0; j < a->name.size(); j++) { fpackf(tfile, "Bb", a->name[j]); } } diff --git a/Source/Account.h b/Source/Account.h index 53d3c94..2d75f55 100644 --- a/Source/Account.h +++ b/Source/Account.h @@ -45,7 +45,7 @@ class Account public: static void destroy(int i); static Account* destroy(Account* a); - static Account* add(std::string name); + static Account* add(const std::string& name); static Account* get(int i); static Account* loadFile(std::string filename); static void saveFile(std::string filename, Account* accountactive); @@ -103,13 +103,13 @@ public: std::string getCurrentCampaign() { return currentCampaign; }; - void setCurrentCampaign(std::string name); + void setCurrentCampaign(const std::string& name); static int getNbAccounts() { return accounts.size(); }; private: - Account(std::string n = ""); + Account(const std::string& name = ""); int difficulty; int progress; // progress in challenge levels float points; diff --git a/Source/Animation.h b/Source/Animation.h index ed6f278..f5ac6b4 100644 --- a/Source/Animation.h +++ b/Source/Animation.h @@ -28,7 +28,6 @@ enum anim_height_type { lowheight, middleheight, highheight }; - enum animation_types { #define DECLARE_ANIM(id, ...) id, #include "Animation.def" diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 93766d3..af0eb18 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -931,10 +931,9 @@ int Game::DrawGLScene(StereoSide side) //Hot spots if (numhotspots && (bonustime >= 1 || bonus <= 0 || bonustime < 0) && !tutoriallevel) { - int closest = -1; float closestdist = -1; float distance = 0; - closest = currenthotspot; + int closest = currenthotspot; for (int i = 0; i < numhotspots; i++) { distance = distsq(&Person::players[0]->coords, &hotspot[i]); if (closestdist == -1 || distance < closestdist) { @@ -1515,8 +1514,6 @@ int Game::DrawGLScene(StereoSide side) } } } - radius = fast_sqrt(maxdistance); - radius = 110; glScalef(.25 / radius * 256 * terrain.scale * .4, .25 / radius * 256 * terrain.scale * .4, 1); diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index 6daef2b..c19db02 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -162,9 +162,6 @@ void Game::deleteGame() void LoadSave(const char *fileName, GLuint *textureid, bool mipmap, GLubyte *array, int *skinsize) { - int i; - int bytesPerPixel; - LOGFUNC; LOG(std::string("Loading (S)...") + fileName); @@ -172,8 +169,6 @@ void LoadSave(const char *fileName, GLuint *textureid, bool mipmap, GLubyte *arr //Load Image float temptexdetail = texdetail; texdetail = 1; - //upload_image( fileName ); - //LoadTGA( fileName ); // Converting file to something os specific char * fixedFN = ConvertFileName(fileName); @@ -185,16 +180,13 @@ void LoadSave(const char *fileName, GLuint *textureid, bool mipmap, GLubyte *arr upload_image( fileNamep , 0); texdetail = temptexdetail; - //Is it valid? - if (1 == 1) { - bytesPerPixel = texture.bpp / 8; + int bytesPerPixel = texture.bpp / 8; - int tempnum = 0; - for (i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) { - if ((i + 1) % 4 || bytesPerPixel == 3) { - array[tempnum] = texture.data[i]; - tempnum++; - } + int tempnum = 0; + for (int i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) { + if ((i + 1) % 4 || bytesPerPixel == 3) { + array[tempnum] = texture.data[i]; + tempnum++; } } } @@ -640,10 +632,8 @@ void Game::InitGame() LOG("Initializing sound system..."); #if PLATFORM_LINUX - int output = -1; - unsigned char rc = 0; - output = OPENAL_OUTPUT_ALSA; // Try alsa first... + int output = OPENAL_OUTPUT_ALSA; // Try alsa first... if (cmdline("forceoss")) // ...but let user override that. output = OPENAL_OUTPUT_OSS; else if (cmdline("nosound")) diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index c693e1c..8a7a54e 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -3888,7 +3888,7 @@ void doAerialAcrobatics() } } - if (tempcollide && (/*Person::players[k]->jumptogglekeydown*/1 == 1 || Person::players[k]->aitype != playercontrolled)) + if (tempcollide) for (int l = 0; l < terrain.patchobjectnum[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz]; l++) { int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l]; lowpoint = Person::players[k]->coords; @@ -3970,7 +3970,6 @@ void doAerialAcrobatics() if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim) break; if (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim) { - lowpoint = DoRotation(objects.model[i].facenormals[whichhit], 0, objects.yaw[k], 0); lowpoint = Person::players[k]->coords; lowpoint.y += (float)j / 13; lowpointtarget = lowpoint + facing * 1.3; @@ -7196,7 +7195,6 @@ void Game::Tick() Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim || Person::players[i]->isFlip() || - Person::players[i]->isFlip() || Person::players[i]->aitype != playercontrolled)) { for (unsigned j = 0; j < weapons.size(); j++) { if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 || diff --git a/Source/MacCompatibility.cpp b/Source/MacCompatibility.cpp index 272288a..7d04905 100644 --- a/Source/MacCompatibility.cpp +++ b/Source/MacCompatibility.cpp @@ -215,10 +215,8 @@ static inline const char *getPrefPath(void) static int locateCorrectCase(char *buf, bool makedirs) { int rc; - char *ptr; - char *prevptr; + char *ptr = buf; - ptr = prevptr = buf; while (ptr = strchr(ptr + 1, '/')) { *ptr = '\0'; /* block this path section off */ rc = locateOneElement(buf); diff --git a/Source/Objects.cpp b/Source/Objects.cpp index 15eb793..2a8474b 100644 --- a/Source/Objects.cpp +++ b/Source/Objects.cpp @@ -362,152 +362,148 @@ void Objects::Draw() hidden = distsqflat(&viewer, &position[i]) <= playerdist + 3; if (hidden) { distance = 1; - if (distance > 0) { - if (1 == 1 || occluded[i] < 6) { - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glEnable(GL_LIGHTING); - glDepthMask(1); - glTranslatef(position[i].x, position[i].y, position[i].z); - if (type[i] == bushtype) { - messedwith[i] -= multiplier; - if (rotxvel[i] || rotx[i]) { - if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); - if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]); - if (rotx[i] > 0) rotxvel[i] -= multiplier * 4; - if (rotx[i] < 0) rotxvel[i] += multiplier * 4; - if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4; - if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4; - if (fabs(rotx[i]) < multiplier * 4) - rotx[i] = 0; - if (fabs(rotxvel[i]) < multiplier * 4) - rotxvel[i] = 0; - - rotx[i] += rotxvel[i] * multiplier * 4; - } - if (rotyvel[i] || roty[i]) { - if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]); - if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]); - if (roty[i] > 0) rotyvel[i] -= multiplier * 4; - if (roty[i] < 0) rotyvel[i] += multiplier * 4; - if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4; - if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4; - if (fabs(roty[i]) < multiplier * 4) - roty[i] = 0; - if (fabs(rotyvel[i]) < multiplier * 4) - rotyvel[i] = 0; - - roty[i] += rotyvel[i] * multiplier * 4; - } - if (roty[i]) { - glRotatef(roty[i], 1, 0, 0); - } - if (rotx[i]) { - glRotatef(-rotx[i], 0, 0, 1); - } - if (rotx[i] > 10) - rotx[i] = 10; - if (rotx[i] < -10) - rotx[i] = -10; - if (roty[i] > 10) - roty[i] = 10; - if (roty[i] < -10) - roty[i] = -10; - } - if (type[i] == treetrunktype || type[i] == treeleavestype) { - messedwith[i] -= multiplier; - if (rotxvel[i] || rotx[i]) { - if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); - if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]); - if (rotx[i] > 0) rotxvel[i] -= multiplier * 4; - if (rotx[i] < 0) rotxvel[i] += multiplier * 4; - if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4; - if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4; - if (fabs(rotx[i]) < multiplier * 4) - rotx[i] = 0; - if (fabs(rotxvel[i]) < multiplier * 4) - rotxvel[i] = 0; - - rotx[i] += rotxvel[i] * multiplier * 4; - } - if (rotyvel[i] || roty[i]) { - if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]); - if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]); - if (roty[i] > 0) rotyvel[i] -= multiplier * 4; - if (roty[i] < 0) rotyvel[i] += multiplier * 4; - if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4; - if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4; - if (fabs(roty[i]) < multiplier * 4) - roty[i] = 0; - if (fabs(rotyvel[i]) < multiplier * 4) - rotyvel[i] = 0; - - roty[i] += rotyvel[i] * multiplier * 4; - } - if (roty[i]) { - glRotatef(roty[i] / 2, 1, 0, 0); - } - if (rotx[i]) { - glRotatef(-rotx[i] / 2, 0, 0, 1); - } - if (rotx[i] > 10) - rotx[i] = 10; - if (rotx[i] < -10) - rotx[i] = -10; - if (roty[i] > 10) - roty[i] = 10; - if (roty[i] < -10) - roty[i] = -10; - } - if (environment == snowyenvironment) { - if (type[i] == treeleavestype) { - glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - if (type[i] == treetrunktype) { - glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - if (type[i] == bushtype) { - glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - } - if (environment == grassyenvironment) { - if (type[i] == treeleavestype) { - glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - if (type[i] == treetrunktype) { - glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - if (type[i] == bushtype) { - glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); - } - } - glRotatef(yaw[i], 0, 1, 0); - glColor4f(1, 1, 1, distance); - if (type[i] == treeleavestype) { - glDisable(GL_CULL_FACE); - glDisable(GL_LIGHTING); - terrainlight = terrain.getLighting(position[i].x, position[i].z); - glDepthMask(0); - glEnable(GL_BLEND); - glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3); - glAlphaFunc(GL_GREATER, 0); - glDisable(GL_ALPHA_TEST); - model[i].drawdifftex(treetextureptr); - } - if (type[i] == bushtype) { - glDisable(GL_CULL_FACE); - glDisable(GL_LIGHTING); - terrainlight = terrain.getLighting(position[i].x, position[i].z); - glDepthMask(0); - glEnable(GL_BLEND); - glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3); - glAlphaFunc(GL_GREATER, 0); - glDisable(GL_ALPHA_TEST); - model[i].drawdifftex(bushtextureptr); - } - glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glEnable(GL_LIGHTING); + glDepthMask(1); + glTranslatef(position[i].x, position[i].y, position[i].z); + if (type[i] == bushtype) { + messedwith[i] -= multiplier; + if (rotxvel[i] || rotx[i]) { + if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); + if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]); + if (rotx[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotx[i] < 0) rotxvel[i] += multiplier * 4; + if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4; + if (fabs(rotx[i]) < multiplier * 4) + rotx[i] = 0; + if (fabs(rotxvel[i]) < multiplier * 4) + rotxvel[i] = 0; + + rotx[i] += rotxvel[i] * multiplier * 4; } + if (rotyvel[i] || roty[i]) { + if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]); + if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]); + if (roty[i] > 0) rotyvel[i] -= multiplier * 4; + if (roty[i] < 0) rotyvel[i] += multiplier * 4; + if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4; + if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4; + if (fabs(roty[i]) < multiplier * 4) + roty[i] = 0; + if (fabs(rotyvel[i]) < multiplier * 4) + rotyvel[i] = 0; + + roty[i] += rotyvel[i] * multiplier * 4; + } + if (roty[i]) { + glRotatef(roty[i], 1, 0, 0); + } + if (rotx[i]) { + glRotatef(-rotx[i], 0, 0, 1); + } + if (rotx[i] > 10) + rotx[i] = 10; + if (rotx[i] < -10) + rotx[i] = -10; + if (roty[i] > 10) + roty[i] = 10; + if (roty[i] < -10) + roty[i] = -10; + } + if (type[i] == treetrunktype || type[i] == treeleavestype) { + messedwith[i] -= multiplier; + if (rotxvel[i] || rotx[i]) { + if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]); + if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]); + if (rotx[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotx[i] < 0) rotxvel[i] += multiplier * 4; + if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4; + if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4; + if (fabs(rotx[i]) < multiplier * 4) + rotx[i] = 0; + if (fabs(rotxvel[i]) < multiplier * 4) + rotxvel[i] = 0; + + rotx[i] += rotxvel[i] * multiplier * 4; + } + if (rotyvel[i] || roty[i]) { + if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]); + if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]); + if (roty[i] > 0) rotyvel[i] -= multiplier * 4; + if (roty[i] < 0) rotyvel[i] += multiplier * 4; + if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4; + if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4; + if (fabs(roty[i]) < multiplier * 4) + roty[i] = 0; + if (fabs(rotyvel[i]) < multiplier * 4) + rotyvel[i] = 0; + + roty[i] += rotyvel[i] * multiplier * 4; + } + if (roty[i]) { + glRotatef(roty[i] / 2, 1, 0, 0); + } + if (rotx[i]) { + glRotatef(-rotx[i] / 2, 0, 0, 1); + } + if (rotx[i] > 10) + rotx[i] = 10; + if (rotx[i] < -10) + rotx[i] = -10; + if (roty[i] > 10) + roty[i] = 10; + if (roty[i] < -10) + roty[i] = -10; + } + if (environment == snowyenvironment) { + if (type[i] == treeleavestype) { + glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + if (type[i] == treetrunktype) { + glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + if (type[i] == bushtype) { + glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + } + if (environment == grassyenvironment) { + if (type[i] == treeleavestype) { + glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + if (type[i] == treetrunktype) { + glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + if (type[i] == bushtype) { + glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0); + } + } + glRotatef(yaw[i], 0, 1, 0); + glColor4f(1, 1, 1, distance); + if (type[i] == treeleavestype) { + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + terrainlight = terrain.getLighting(position[i].x, position[i].z); + glDepthMask(0); + glEnable(GL_BLEND); + glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3); + glAlphaFunc(GL_GREATER, 0); + glDisable(GL_ALPHA_TEST); + model[i].drawdifftex(treetextureptr); + } + if (type[i] == bushtype) { + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + terrainlight = terrain.getLighting(position[i].x, position[i].z); + glDepthMask(0); + glEnable(GL_BLEND); + glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3); + glAlphaFunc(GL_GREATER, 0); + glDisable(GL_ALPHA_TEST); + model[i].drawdifftex(bushtextureptr); } + glPopMatrix(); } } } diff --git a/Source/Person.cpp b/Source/Person.cpp index 3327f5a..55b58c2 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -1018,7 +1018,7 @@ void Person::Reverse() victim->animCurrent = knifeslashreversalanim; victim->animTarget = knifeslashreversalanim; } - if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim && animTarget != swordslashanim) { + if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim) { victim->targettilt2 = targettilt2; victim->frameCurrent = frameCurrent; victim->frameTarget = frameTarget; @@ -1459,7 +1459,6 @@ void Person::RagDoll(bool checkcollision) skeleton.joints[i].locked = 0; skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0); if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0); - if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = skeleton.joints[i].position; if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = coords; skeleton.joints[i].position.y += .1; skeleton.joints[i].oldposition = skeleton.joints[i].position; @@ -5418,7 +5417,7 @@ void Person::DoStuff() } } - if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim || animTarget == blockhighleftanim) { + if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim) { //close hands and mouth if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) { righthandmorphness = 0; diff --git a/Source/Skeleton.cpp b/Source/Skeleton.cpp index b951830..fe99c32 100644 --- a/Source/Skeleton.cpp +++ b/Source/Skeleton.cpp @@ -48,7 +48,6 @@ extern bool visibleloading; void dealloc2(void* param) { free(param); - param = 0; // FIXME: does this *do* anything??? } enum {boneconnect, constraint, muscle}; @@ -553,7 +552,16 @@ void Skeleton::DoGravity(float *scale) { static int i; for (i = 0; i < num_joints; i++) { - if (((joints[i].label != leftknee && joints[i].label != rightknee) || lowforward.y > -.1 || joints[i].mass < 5) && ((joints[i].label != rightelbow && joints[i].label != rightelbow) || forward.y < .3)) + if ( + ( + ((joints[i].label != leftknee) && (joints[i].label != rightknee)) || + (lowforward.y > -.1) || + (joints[i].mass < 5) + ) && ( + ((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) || + (forward.y < .3) + ) + ) joints[i].velocity.y += gravity * multiplier / (*scale); } } @@ -1088,11 +1096,9 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c fseek ( tfile, lSize, SEEK_CUR); } - // ??? - lSize = sizeof(int); for (j = 0; j < num_muscles; j++) { for (i = 0; i < muscles[j].numverticeslow; i++) { - if (muscles[j].numverticeslow && muscles[j].verticeslow[i] < modellow.vertexNum) + if (muscles[j].verticeslow[i] < modellow.vertexNum) modellow.owner[muscles[j].verticeslow[i]] = j; } } @@ -1422,9 +1428,7 @@ Animation & Animation::operator = (const Animation & ani) { int i = 0; - bool allocate = true; - - allocate = ((ani.numframes != numframes) || (ani.joints != joints)); + bool allocate = ((ani.numframes != numframes) || (ani.joints != joints)); if (allocate) deallocate(); @@ -1434,6 +1438,7 @@ Animation & Animation::operator = (const Animation & ani) attack = ani.attack; joints = ani.joints; weapontargetnum = ani.weapontargetnum; + offset = ani.offset; if (allocate) position = (XYZ**)malloc(sizeof(XYZ*)*ani.joints); diff --git a/Source/Sprite.cpp b/Source/Sprite.cpp index 5b7c9e1..3d9a50c 100644 --- a/Source/Sprite.cpp +++ b/Source/Sprite.cpp @@ -277,7 +277,7 @@ void Sprite::Draw() glPopMatrix(); } tempmult = multiplier; - for (unsigned i = sprites.size() - 1; i >= 0; i--) { + for (int i = sprites.size() - 1; i >= 0; i--) { multiplier = tempmult; if (sprites[i]->type != snowsprite) { sprites[i]->position += sprites[i]->velocity * multiplier; @@ -416,7 +416,7 @@ void Sprite::Draw() DeleteSprite(i); } if (check) - for (unsigned i = sprites.size() - 1; i >= 0; i--) { + for (int i = sprites.size() - 1; i >= 0; i--) { sprites[i]->oldposition = sprites[i]->position; } glAlphaFunc(GL_GREATER, 0.0001); diff --git a/Source/Terrain.cpp b/Source/Terrain.cpp index a50dd52..ea3b802 100644 --- a/Source/Terrain.cpp +++ b/Source/Terrain.cpp @@ -432,34 +432,14 @@ bool Terrain::load(const char *fileName) texdetail = temptexdetail; - size = 128; - if (1 == 1) { - /*if ( texture.bpp == 24 ) - type = GL_RGB; - else - type = GL_RGBA; + size = texture.sizeX; - glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); - - if(!terraintexture)glGenTextures( 1, &terraintexture ); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - - glBindTexture( GL_TEXTURE_2D, terraintexture); - //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - - gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data ); - */ - - size = texture.sizeX; - - for (i = 0; i < size; i++) { - for (j = 0; j < size; j++) { - heightmap[size - 1 - i][j] = (float)((texture.data[(i + (j * size)) * texture.bpp / 8])) / 5; - } + for (i = 0; i < size; i++) { + for (j = 0; j < size; j++) { + heightmap[size - 1 - i][j] = (float)((texture.data[(i + (j * size)) * texture.bpp / 8])) / 5; } - } + if (visibleloading) Game::LoadingScreen(); @@ -770,7 +750,6 @@ void Terrain::CalculateNormals() for (i = 0; i < size; i++) { for (j = 0; j < size; j++) { Normalise(&normals[i][j]); - normals[i][j] = normals[i][j]; } } } -- 2.39.2